Coverage and mutants
A test can run every line of your code, and both sides of every if, without checking what any of
it does. Coverage scores it the same as a test that checks everything, so the report is green
while the tests would pass on code that’s wrong. mutastic asks the question coverage can’t: it
puts a small bug in the code, runs the tests, and tells you when they don’t notice.
This page measures one small example both ways, with tests that check too little and tests that
check the results. Coverage can’t tell them apart, and mutastic can. Then it shows where mutants
reach past branch coverage even for good tests, and when --operators=stronger finds more than
the defaults.
Three ways to measure tests
Section titled “Three ways to measure tests”- Line coverage asks which lines ran. A line no test runs is untested, for sure. A line that ran may be untested too: running it isn’t checking it.
- Branch coverage asks which way each decision went: whether the tests took each
ifboth ways. It finds the side of a condition no test takes. It still doesn’t look at what the tests assert. - Mutation testing asks whether the tests would notice a bug. mutastic makes one small change to the code at a time, a mutant, and runs the tests that reach it. A mutant they catch is code they check. One they miss is a gap, on a line coverage counts as tested.
Coverage is cheap, and it tells you where tests never go. Only mutants tell you whether the tests check what they reach.
The example
Section titled “The example”The example works out what an order costs:
public class Checkout { /// 10% off orders of 100 or more. public int discount(int total) { if (total >= 100) { return total / 10; } return 0; }
/// What `quantity` items at `price` each cost, less any discount, which goes on the receipt. public int pay(int quantity, int price, List<String> receipt) { int total = quantity * price; int off = discount(total); receipt.add("discount " + off); return total - off; }}In fixtures/checkout/src/lib.rs, in mutastic for Rust’s repository:
/// 10% off orders of 100 or more.pub fn discount(total: u32) -> u32 { if total >= 100 { return total / 10; } 0}
/// What `quantity` items at `price` each cost, less any discount, which goes on the receipt.pub fn pay(quantity: u32, price: u32, receipt: &mut Vec<String>) -> u32 { let total = quantity * price; let off = discount(total); receipt.push(format!("discount {off}")); total - off}In samples/checkout/Sources/Checkout/Checkout.swift, in mutastic for Swift’s repository:
/// What an order costs.public struct Checkout: Sendable { public init() {}
/// 10% off orders of 100 or more. public func discount(total: Int) -> Int { if total >= 100 { return total / 10 } return 0 }
/// What `quantity` items at `price` each cost, less any /// discount, which goes on the receipt. public func pay( quantity: Int, price: Int, receipt: inout [String] ) -> Int { let total = quantity * price let off = discount(total: total) receipt.append("discount \(off)") return total - off }}Two sets of tests, the same coverage
Section titled “Two sets of tests, the same coverage”Its tests run every line, and take the if both ways: a big order gets the discount and a small
one doesn’t. But one checks only that a big order costs less than 250, and the other checks
nothing at all:
class CheckoutTest { @Test void bigOrdersGetADiscount() { var receipt = new ArrayList<String>(); assertTrue(new Checkout().pay(1, 250, receipt) < 250); }
@Test void smallOrdersPayFullPrice() { new Checkout().pay(1, 50, new ArrayList<>()); }}#[test]fn big_orders_get_a_discount() { let mut receipt = Vec::new(); assert!(pay(1, 250, &mut receipt) < 250);}
#[test]fn small_orders_pay_full_price() { pay(1, 50, &mut Vec::new());}@Test func bigOrdersGetADiscount() { var receipt: [String] = [] let paid = Checkout().pay( quantity: 1, price: 250, receipt: &receipt) #expect(paid < 250)}
@Test func smallOrdersPayFullPrice() { var receipt: [String] = [] _ = Checkout().pay(quantity: 1, price: 50, receipt: &receipt)}These check the results: what each order costs, and what goes on the receipt.
With import static org.junit.jupiter.api.Assertions.assertEquals; and import java.util.List;
at the top of the file:
@Testvoid bigOrdersGetADiscount() { var receipt = new ArrayList<String>(); assertEquals(225, new Checkout().pay(1, 250, receipt)); assertEquals(List.of("discount 25"), receipt);}
@Testvoid smallOrdersPayFullPrice() { var receipt = new ArrayList<String>(); assertEquals(50, new Checkout().pay(1, 50, receipt)); assertEquals(List.of("discount 0"), receipt);}#[test]fn big_orders_get_a_discount() { let mut receipt = Vec::new(); assert_eq!(pay(1, 250, &mut receipt), 225); assert_eq!(receipt, ["discount 25"]);}
#[test]fn small_orders_pay_full_price() { let mut receipt = Vec::new(); assert_eq!(pay(1, 50, &mut receipt), 50); assert_eq!(receipt, ["discount 0"]);}@Test func bigOrdersGetADiscount() { var receipt: [String] = [] let paid = Checkout().pay( quantity: 1, price: 250, receipt: &receipt) #expect(paid == 225) #expect(receipt == ["discount 25"])}
@Test func smallOrdersPayFullPrice() { var receipt: [String] = [] let paid = Checkout().pay( quantity: 1, price: 50, receipt: &receipt) #expect(paid == 50) #expect(receipt == ["discount 0"])}JaCoCo measures their coverage. The sample’s build applies its Gradle plugin, and its CSV report has the counts:
./gradlew test jacocoTestReport| Tests | Lines | Branches |
|---|---|---|
| Checking too little | 8 of 8 | 2 of 2 |
| Checking the results | 8 of 8 | 2 of 2 |
Every line ran, and the if went both ways, with either set of tests.
cargo llvm-cov measures their coverage:
cargo llvm-cov --manifest-path fixtures/checkout/Cargo.toml --lcov --summary-only --remap-path-prefixWith the tests that check too little:
SF:src/lib.rsFNF:2FNH:2BRF:0BRH:0LF:12LH:12end_of_recordWith the tests that check the results:
SF:src/lib.rsFNF:2FNH:2BRF:0BRH:0LF:12LH:12end_of_recordThe same, to the last line. In lcov’s terms, LF is the lines found and LH the lines hit, and
FNF and FNH the same for functions: every one ran, both times. BRF and BRH, the branches,
are 0 because branch coverage in Rust needs a nightly compiler (cargo +nightly llvm-cov --branch).
The Swift toolchain’s llvm-cov measures their coverage, from a test run with coverage on, one
test at a time: its counters aren’t atomic, so tests side by side can lose a count and show a line
as missed. On Linux the tests are in checkoutPackageTests.xctest:
swift test --enable-code-coverage --no-parallel \ --package-path samples/checkoutllvm-cov export -format=lcov -summary-only \ -instr-profile \ samples/checkout/.build/debug/codecov/default.profdata \ samples/checkout/.build/debug/checkoutPackageTests.xctest \ -ignore-filename-regex='(\.build|Tests)/'On macOS, llvm-cov is Xcode’s, run as xcrun llvm-cov, and the tests are in that bundle’s
Contents/MacOS/checkoutPackageTests.
With the tests that check too little:
SF:/home/you/project/samples/checkout/Sources/Checkout/Checkout.swiftFNF:3FNH:3BRF:0BRH:0LF:13LH:13end_of_recordWith the tests that check the results:
SF:/home/you/project/samples/checkout/Sources/Checkout/Checkout.swiftFNF:3FNH:3BRF:0BRH:0LF:13LH:13end_of_recordThe same, to the last line. In lcov’s terms, LF is the lines found and LH the lines hit, and
FNF and FNH the same for functions: every one ran, both times. BRF and BRH, the branches,
are 0 because llvm-cov counts no branches in Swift.
What mutastic sees
Section titled “What mutastic sees”The tests that check too little:
mutastic run samples/checkout --format=concise Missed ──────────────────────────────────────────────────────────── ✗ src/main/java/com/example/checkout/Checkout.java:8 no test checks discount() at total == 100 mc5ea6505 ✗ src/main/java/com/example/checkout/Checkout.java:8 no test needs total >= 100 to be false in discount() m56bd9867 ✗ src/main/java/com/example/checkout/Checkout.java:9 tests pass even when / becomes * in discount() mee8d2a4d ✗ src/main/java/com/example/checkout/Checkout.java:11 no test checks discount() returning 0 here mf4e4c49c ✗ src/main/java/com/example/checkout/Checkout.java:16 tests pass even when * becomes / in pay() m21faa923 ✗ src/main/java/com/example/checkout/Checkout.java:18 no test checks the effect of calling add() in pay() md47a74cb ✗ src/main/java/com/example/checkout/Checkout.java:19 no test checks what pay() returns here m6073d12b
Next: mutastic verify <id> samples/checkout · mutastic run --only=<id> samples/checkout · mutastic explain <id> samples/checkout
Classes 0 clean | 1 with misses Mutants ✓ 3 caught · ✗ 7 missed (10) Worst at Checkout.discount() 4 ✗ · Checkout.pay() 3 ✗ Test runs 17 (20 without coverage selection) Start at 19:09:33 Duration 1.7s (setup 0ms, build 441ms, coverage 190ms, mutants 146ms, checking 949ms, reports 12ms) Tests 2 on JDK 17 · 1 worker Reports samples/checkout/build/mutastic/mutation.json · samples/checkout/build/mutastic/mutation.html Score 30.0% FAIL Below the threshold of 80: 7 missed, 0 not covered.mutastic run fixtures/checkout --format=concise Missed ──────────────────────────────────────────────────────────── ✗ src/lib.rs:6 no test checks discount() at total == 100 ma4286e9f,ma7d1f59d ✗ src/lib.rs:9 no test checks discount() returning 0 here m669a0afd ✗ src/lib.rs:14 tests pass even when * becomes / in pay() m3590a884 ✗ src/lib.rs:16 no test checks what receipt.push(format!("discount {off}")); does in pay() ma1e58306 ✗ src/lib.rs:17 no test checks what pay() returns here mc509a35e
Next: mutastic verify <id> fixtures/checkout · mutastic run --only=<id> fixtures/checkout · mutastic explain <id> fixtures/checkout
Files 0 clean | 1 with misses Mutants ✓ 4 caught · ✗ 6 missed (10) Worst at discount() 3 ✗ · pay() 3 ✗ Build one build of every mutant, 2 rounds (check and build) Test runs 17 (20 without coverage selection) Start at 18:54:26 Duration 617ms (setup 32ms, build 540ms, coverage 2ms, mutants 20ms, checking 2ms, reports 2ms) Tests 2 on rustc 1.99.1 · 4 workers Reports fixtures/checkout/target/mutastic/mutation.json · fixtures/checkout/target/mutastic/mutation.html Score 40.0% FAIL Below the threshold of 80: 6 missed, 0 not covered.mutastic run samples/checkout --format=concise Missed ──────────────────────────────────────────────────────────── ✗ Sources/Checkout/Checkout.swift:7 no test checks discount() at total == 100 m43d84c50,m35f672d7 ✗ Sources/Checkout/Checkout.swift:8 tests pass even when / becomes * in discount() md9aee958 ✗ Sources/Checkout/Checkout.swift:10 no test checks discount() returning 0 here m654d7ba3 ✗ Sources/Checkout/Checkout.swift:18 tests pass even when * becomes / in pay() meb564ded ✗ Sources/Checkout/Checkout.swift:20 no test checks what receipt.append("discount \(off)") does in pay() mfb65b39e ✗ Sources/Checkout/Checkout.swift:21 no test checks what pay() returns here m2f1dc17a
Next: mutastic verify <id> samples/checkout · mutastic run --only=<id> samples/checkout · mutastic explain <id> samples/checkout
Files 0 clean | 1 with misses Mutants ✓ 3 caught · ✗ 7 missed (10) Worst at Checkout.discount() 4 ✗ · Checkout.pay() 3 ✗ Build one build of every mutant, 1 round (build) Test runs 17 (20 without coverage selection) Start at 22:29:00 Duration 6.2s (setup 34ms, build 6.0s, coverage 22ms, mutants 115ms, checking 21ms, reports 19ms) Tests 2 on swift 6.3.3 · 4 workers Reports samples/checkout/.build/mutastic/mutation.json · samples/checkout/.build/mutastic/mutation.html Score 30.0% FAIL Below the threshold of 80: 7 missed, 0 not covered.Each mutant under Missed is a bug those tests let through, on code that coverage counts as
tested. With the tests that check the results, mutastic catches all of them but one, and that one
is the first of the next section.
Where mutants go further than branches
Section titled “Where mutants go further than branches”Boundaries
Section titled “Boundaries”The tests that check the results take the if both ways, at 50 and 250. Branch coverage asks for
nothing more. But no test is at 100, so >= and > give the same answer on every test, and the
off-by-one bug passes:
mutastic run samples/checkout Missed ────────────────────────────────────────────────────────────
❯ src/main/java/com/example/checkout/Checkout.java 1 missed in 1 method
✗ MISSED no test checks discount() at total == 100 ┌─ src/main/java/com/example/checkout/Checkout.java:8 │ 7 │ public int discount(int total) { 8 │ if (total >= 100) { │ ^^ >= changed to > 9 │ return total / 10; │ = mutant - if (total >= 100) { + if (total > 100) { = operator mutastic/boundary · https://docs.mutastic.io/java/operators/conditions/#boundary = note: every test calls discount() away from the boundary inputs seen: 50, 250 (none is 100) covered by CheckoutTest#bigOrdersGetADiscount, CheckoutTest#smallOrdersPayFullPrice (all 2 covering tests still pass) = help: test discount() with total = 100 and assert the result
// in CheckoutTest @Test void discountAtTheTotalEdge() { assertEquals(10, new Checkout().discount(100)); // today 10 · with this mutant 0 } check today's value is the one you intend: the test pins what the code does now
done when mutastic verify mc5ea6505 samples/checkout passes reproduce mutastic run --only=mc5ea6505 samples/checkout or ignore mutastic ignore mc5ea6505 --reason="<why>" samples/checkout
Next: mutastic verify <id> samples/checkout · mutastic run --only=<id> samples/checkout · mutastic explain <id> samples/checkout
Classes 0 clean | 1 with misses Mutants ✓ 9 caught · ✗ 1 missed (10) Worst at Checkout.discount() 1 ✗ Test runs 13 (20 without coverage selection) Start at 03:35:54 Duration 1.8s (setup 0ms, build 458ms, coverage 198ms, mutants 113ms, checking 1.1s, reports 10ms) Tests 2 on JDK 17 · 1 worker Reports samples/checkout/build/mutastic/mutation.json · samples/checkout/build/mutastic/mutation.html Score 90.0% PASS 1 missed, above the threshold of 80.mutastic run fixtures/checkout Missed ────────────────────────────────────────────────────────────
❯ src/lib.rs 1 missed in 1 function
✗ MISSED no test checks discount() at total == 100 ┌─ src/lib.rs:6 │ 5 │ pub fn discount(total: u32) -> u32 { 6 │ if total >= 100 { │ ^^ >= changed to > 7 │ return total / 10; │ = mutant - if total >= 100 { + if total > 100 { = operator mutastic/boundary · https://docs.mutastic.io/rust/operators/conditions/#boundary = note: every test calls discount() away from the boundary inputs seen: 50, 250 (none is 100) covered by checkout::big_orders_get_a_discount, checkout::small_orders_pay_full_price (all 2 covering tests still pass) = help: test discount() with total = 100 and assert the result
// in a new #[cfg(test)] mod tests in src/lib.rs #[test] fn discount_at_the_total_edge() { assert_eq!(super::discount(100), 10); // today 10 · with this mutant 0 } check today's value is the one you intend: the test pins what the code does now
done when mutastic verify ma4286e9f fixtures/checkout passes reproduce mutastic run --only=ma4286e9f fixtures/checkout or ignore mutastic ignore ma4286e9f --reason="<why>" fixtures/checkout
Next: mutastic verify <id> fixtures/checkout · mutastic run --only=<id> fixtures/checkout · mutastic explain <id> fixtures/checkout
Files 0 clean | 1 with misses Mutants ✓ 9 caught · ✗ 1 missed (10) Worst at discount() 1 ✗ Build one build of every mutant, 2 rounds (check and build) Test runs 17 (20 without coverage selection) Start at 09:44:14 Duration 1.8s (setup 275ms, build 1.4s, coverage 6ms, mutants 58ms, checking 15ms, reports 4ms) Tests 2 on rustc 1.100.0 · 4 workers Reports fixtures/checkout/target/mutastic/mutation.json · fixtures/checkout/target/mutastic/mutation.html Score 90.0% PASS 1 missed, above the threshold of 80.mutastic run samples/checkout Missed ────────────────────────────────────────────────────────────
❯ Sources/Checkout/Checkout.swift 1 missed in 1 function
✗ MISSED no test checks discount() at total == 100 ┌─ Sources/Checkout/Checkout.swift:7 │ 6 │ public func discount(total: Int) -> Int { 7 │ if total >= 100 { │ ^^ >= changed to > 8 │ return total / 10 │ = mutant - if total >= 100 { + if total > 100 { = operator mutastic/boundary · https://docs.mutastic.io/swift/operators/conditions/#boundary = note: every test calls discount() away from the boundary inputs seen: 50, 250 (none is 100) covered by CheckoutTests.bigOrdersGetADiscount(), CheckoutTests.smallOrdersPayFullPrice() (all 2 covering tests still pass) = help: test discount() with total = 100 and assert the result
// in Tests/CheckoutTests/CheckoutTests.swift @Test func discountAtTheTotalEdge() { #expect(Checkout().discount(total: 100) == 10) // today 10 · with this mutant 0 } check today's value is the one you intend: the test pins what the code does now
done when mutastic verify m43d84c50 samples/checkout passes reproduce mutastic run --only=m43d84c50 samples/checkout or ignore mutastic ignore m43d84c50 --reason="<why>" samples/checkout
Next: mutastic verify <id> samples/checkout · mutastic run --only=<id> samples/checkout · mutastic explain <id> samples/checkout
Files 0 clean | 1 with misses Mutants ✓ 9 caught · ✗ 1 missed (10) Worst at Checkout.discount() 1 ✗ Build one build of every mutant, 1 round (build) Test runs 17 (20 without coverage selection) Start at 22:29:11 Duration 1.1s (setup 28ms, build 917ms, coverage 22ms, mutants 92ms, checking 21ms, reports 20ms) Tests 2 on swift 6.3.3 · 4 workers Reports samples/checkout/.build/mutastic/mutation.json · samples/checkout/.build/mutastic/mutation.html Score 90.0% PASS 1 missed, above the threshold of 80. ▲ 60.0 vs last run (code changed)The card asks for a test at 100. Here’s that one, through pay() as the others go, and one just
below the edge, so the edge is pinned from both sides:
@Testvoid ordersOf100GetADiscount() { assertEquals(90, new Checkout().pay(1, 100, new ArrayList<>()));}
@Testvoid ordersJustUnder100PayFullPrice() { assertEquals(99, new Checkout().pay(1, 99, new ArrayList<>()));}#[test]fn orders_of_100_get_a_discount() { assert_eq!(pay(1, 100, &mut Vec::new()), 90);}
#[test]fn orders_just_under_100_pay_full_price() { assert_eq!(pay(1, 99, &mut Vec::new()), 99);}@Test func ordersOf100GetADiscount() { var receipt: [String] = [] let paid = Checkout().pay( quantity: 1, price: 100, receipt: &receipt) #expect(paid == 90)}
@Test func ordersJustUnder100PayFullPrice() { var receipt: [String] = [] let paid = Checkout().pay( quantity: 1, price: 99, receipt: &receipt) #expect(paid == 99)}Now the run catches every mutant:
mutastic run samples/checkout Classes 1 clean Mutants ✓ 10 caught (10) Test runs 18 (40 without coverage selection) Start at 19:09:41 Duration 2.4s (setup 0ms, build 1.1s, coverage 193ms, mutants 87ms, checking 951ms, reports 10ms) Tests 4 on JDK 17 · 1 worker Reports samples/checkout/build/mutastic/mutation.json · samples/checkout/build/mutastic/mutation.html Score 100.0% PASS Every mutant was caught.mutastic run fixtures/checkout Files 1 clean Mutants ✓ 10 caught (10) Build one build of every mutant, 2 rounds (check and build) Test runs 34 (40 without coverage selection) Start at 18:54:28 Duration 307ms (setup 24ms, build 247ms, coverage 2ms, mutants 9ms, reports 1ms) Tests 4 on rustc 1.99.1 · 4 workers Reports fixtures/checkout/target/mutastic/mutation.json · fixtures/checkout/target/mutastic/mutation.html Score 100.0% PASS Every mutant was caught.mutastic run samples/checkout Files 1 clean Mutants ✓ 10 caught (10) Build one build of every mutant, 1 round (build) Test runs 34 (40 without coverage selection) Start at 22:29:14 Duration 1.2s (setup 27ms, build 980ms, coverage 23ms, mutants 92ms, reports 23ms) Tests 4 on swift 6.3.3 · 4 workers Reports samples/checkout/.build/mutastic/mutation.json · samples/checkout/.build/mutastic/mutation.html Score 100.0% PASS Every mutant was caught. ▲ 10.0 vs last run (code changed)Arithmetic
Section titled “Arithmetic”Every test buys one item, and 1 / 250 is 0. With * changed to /, pay() charges nothing, and
nothing is less than 250, so the test that checks too little still passes. Coverage counted the
line; nothing checked what it worked out.
✗ MISSED tests pass even when * becomes / in pay() ┌─ src/main/java/com/example/checkout/Checkout.java:16 │ 15 │ public int pay(int quantity, int price, List<String> receipt) { 16 │ int total = quantity * price; │ ^ * changed to / 17 │ int off = discount(total); │ = mutant - int total = quantity * price; + int total = quantity / price; = operator mutastic/math · https://docs.mutastic.io/java/operators/arithmetic/#math = note: inputs seen: quantity = 1; price = 50, 250 covered by CheckoutTest#bigOrdersGetADiscount, CheckoutTest#smallOrdersPayFullPrice (all 2 covering tests still pass) = help: use inputs where quantity * price and quantity / price differ, and assert the result
done when mutastic verify m21faa923 samples/checkout passes reproduce mutastic run --only=m21faa923 samples/checkout or ignore mutastic ignore m21faa923 --reason="<why>" samples/checkout ✗ MISSED tests pass even when * becomes / in pay() ┌─ src/lib.rs:14 │ 13 │ pub fn pay(quantity: u32, price: u32, receipt: &mut Vec<String>) -> u32 { 14 │ let total = quantity * price; │ ^ * changed to / 15 │ let off = discount(total); │ = mutant - let total = quantity * price; + let total = quantity / price; = operator mutastic/math · https://docs.mutastic.io/rust/operators/arithmetic/#math = note: inputs seen: price = 50, 250; quantity = 1 covered by checkout::big_orders_get_a_discount, checkout::small_orders_pay_full_price (all 2 covering tests still pass) = help: use inputs where quantity * price and quantity / price differ, and assert the result
done when mutastic verify m3590a884 fixtures/checkout passes reproduce mutastic run --only=m3590a884 fixtures/checkout ✗ MISSED tests pass even when * becomes / in pay() ┌─ Sources/Checkout/Checkout.swift:18 │ 17 │ ) -> Int { 18 │ let total = quantity * price │ ^ * changed to / 19 │ let off = discount(total: total) │ = mutant - let total = quantity * price + let total = quantity / price = operator mutastic/math · https://docs.mutastic.io/swift/operators/arithmetic/#math = note: inputs seen: price = 50, 250; quantity = 1 covered by CheckoutTests.bigOrdersGetADiscount(), CheckoutTests.smallOrdersPayFullPrice() (all 2 covering tests still pass) = help: use inputs where quantity * price and quantity / price differ, and assert the result
done when mutastic verify meb564ded samples/checkout passesReturn values
Section titled “Return values”A test that checks only which way a value went passes for a wrong value too. pay() returning 0
is less than 250:
✗ MISSED no test checks what pay() returns here ┌─ src/main/java/com/example/checkout/Checkout.java:19 │ 18 │ receipt.add("discount " + off); 19 │ return total - off; │ ^^^^^^^^^^^^^^^^^^^ now returns 0 20 │ } │ = mutant - return total - off; + return 0; = operator mutastic/return-value · https://docs.mutastic.io/java/operators/returns/#return-value = note: tests reach this return, but none fails when it returns 0 inputs seen: quantity = 1; price = 50, 250 covered by CheckoutTest#bigOrdersGetADiscount, CheckoutTest#smallOrdersPayFullPrice (all 2 covering tests still pass) = help: assert the value pay() returns on this path, with inputs where it isn't 0
done when mutastic verify m6073d12b samples/checkout passes reproduce mutastic run --only=m6073d12b samples/checkout or ignore mutastic ignore m6073d12b --reason="<why>" samples/checkout ✗ MISSED no test checks what pay() returns here ┌─ src/lib.rs:17 │ 16 │ receipt.push(format!("discount {off}")); 17 │ total - off │ ^^^^^^^^^^^ now returns 0 18 │ } │ = mutant - total - off + 0 = operator mutastic/return-value · https://docs.mutastic.io/rust/operators/returns/#return-value = note: tests reach this return, but none fails when it returns 0 inputs seen: price = 50, 250; quantity = 1 covered by checkout::big_orders_get_a_discount, checkout::small_orders_pay_full_price (all 2 covering tests still pass) = help: assert the value pay() returns on this path, with inputs where it isn't 0
done when mutastic verify mc509a35e fixtures/checkout passes reproduce mutastic run --only=mc509a35e fixtures/checkout ✗ MISSED no test checks what pay() returns here ┌─ Sources/Checkout/Checkout.swift:21 │ 20 │ receipt.append("discount \(off)") 21 │ return total - off │ ^^^^^^^^^^^ now returns 0 22 │ } │ = mutant - return total - off + 0 = operator mutastic/return-value · https://docs.mutastic.io/swift/operators/returns/#return-value = note: tests reach this return, but none fails when it returns 0 inputs seen: price = 50, 250; quantity = 1 covered by CheckoutTests.bigOrdersGetADiscount(), CheckoutTests.smallOrdersPayFullPrice() (all 2 covering tests still pass) = help: assert the value pay() returns on this path, with inputs where it isn't 0
done when mutastic verify m2f1dc17a samples/checkout passesRemoved calls
Section titled “Removed calls”The receipt is what the customer sees, and neither test looks at it. With the line that writes it gone, both pass:
✗ MISSED no test checks the effect of calling add() in pay() ┌─ src/main/java/com/example/checkout/Checkout.java:18 │ 17 │ int off = discount(total); 18 │ receipt.add("discount " + off); │ ^^^ call removed 19 │ return total - off; │ = mutant - receipt.add("discount " + off); = operator mutastic/remove-discarded-call · https://docs.mutastic.io/java/operators/calls/#remove-discarded-call = note: inputs seen: quantity = 1; price = 50, 250 covered by CheckoutTest#bigOrdersGetADiscount, CheckoutTest#smallOrdersPayFullPrice (all 2 covering tests still pass) = help: assert what add() does: the state it changes or the call it makes
done when mutastic verify md47a74cb samples/checkout passes reproduce mutastic run --only=md47a74cb samples/checkout or ignore mutastic ignore md47a74cb --reason="<why>" samples/checkout ✗ MISSED no test checks what receipt.push(format!("discount {off}")); does in pay() ┌─ src/lib.rs:16 │ 15 │ let off = discount(total); 16 │ receipt.push(format!("discount {off}")); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ removed 17 │ total - off │ = mutant - receipt.push(format!("discount {off}")); = operator mutastic/remove-void-call · https://docs.mutastic.io/rust/operators/calls/#remove-void-call = note: inputs seen: price = 50, 250; quantity = 1 covered by checkout::big_orders_get_a_discount, checkout::small_orders_pay_full_price (all 2 covering tests still pass) = help: assert what receipt.push(format!("discount {off}")); changes, in a test of pay()
done when mutastic verify ma1e58306 fixtures/checkout passes reproduce mutastic run --only=ma1e58306 fixtures/checkout ✗ MISSED no test checks what receipt.append("discount \(off)") does in pay() ┌─ Sources/Checkout/Checkout.swift:20 │ 19 │ let off = discount(total: total) 20 │ receipt.append("discount \(off)") │ ^^^^^^^^^^^^^^ removed 21 │ return total - off │ = mutant - receipt.append("discount \(off)") = operator mutastic/remove-void-call · https://docs.mutastic.io/swift/operators/calls/#remove-void-call = note: inputs seen: price = 50, 250; quantity = 1 covered by CheckoutTests.bigOrdersGetADiscount(), CheckoutTests.smallOrdersPayFullPrice() (all 2 covering tests still pass) = help: assert what receipt.append("discount \(off)") changes, in a test of pay()
done when mutastic verify mfb65b39e samples/checkout passesThe tests that check the results catch all three: they assert what pay() returns and what’s on
the receipt.
When the defaults aren’t enough
Section titled “When the defaults aren’t enough”A run uses the defaults set of operators: the changes most likely to find a gap worth a test.
--operators=stronger adds more (see All operators).
Before you pay for a run, mutastic mutants lists what it would make, and runs no test:
mutastic mutants samples/checkout --operators=strongerm1d8dbce7 src/main/java/com/example/checkout/Checkout.java:8:5 mutastic/constant-value the constant 100 becomes 101 in Checkout.discount()m7dc17ea7 src/main/java/com/example/checkout/Checkout.java:8:5 mutastic/constant-value the constant 100 becomes 99 in Checkout.discount()mab1e3cd8 src/main/java/com/example/checkout/Checkout.java:8:5 mutastic/constant-value the constant 100 becomes 0 in Checkout.discount()m0d5e83ae src/main/java/com/example/checkout/Checkout.java:8:5 mutastic/constant-value the constant 100 becomes 1 in Checkout.discount()md6228c60 src/main/java/com/example/checkout/Checkout.java:8:5 mutastic/constant-value the constant 100 becomes -1 in Checkout.discount()mc5ea6505 src/main/java/com/example/checkout/Checkout.java:8:15 mutastic/boundary >= becomes > in Checkout.discount()mff367b6e src/main/java/com/example/checkout/Checkout.java:8:15 mutastic/comparison >= becomes == in Checkout.discount()m28f01dd9 src/main/java/com/example/checkout/Checkout.java:8:15 mutastic/other-comparison >= becomes < in Checkout.discount()m8285ace9 src/main/java/com/example/checkout/Checkout.java:8:15 mutastic/other-comparison >= becomes <= in Checkout.discount()m85a6ca44 src/main/java/com/example/checkout/Checkout.java:8:15 mutastic/other-comparison >= becomes != in Checkout.discount()m310b6020 src/main/java/com/example/checkout/Checkout.java:8:15 mutastic/remove-conditional total >= 100 is always false in Checkout.discount()m56bd9867 src/main/java/com/example/checkout/Checkout.java:8:15 mutastic/remove-conditional total >= 100 is always true in Checkout.discount()m3616c2a8 src/main/java/com/example/checkout/Checkout.java:9:7 mutastic/constant-value the constant 10 becomes 11 in Checkout.discount()meee1003c src/main/java/com/example/checkout/Checkout.java:9:7 mutastic/constant-value the constant 10 becomes 9 in Checkout.discount()m36cc35ce src/main/java/com/example/checkout/Checkout.java:9:7 mutastic/constant-value the constant 10 becomes 0 in Checkout.discount()m04c45bb5 src/main/java/com/example/checkout/Checkout.java:9:7 mutastic/constant-value the constant 10 becomes 1 in Checkout.discount()m7afdd99a src/main/java/com/example/checkout/Checkout.java:9:7 mutastic/constant-value the constant 10 becomes -1 in Checkout.discount()m8cecf405 src/main/java/com/example/checkout/Checkout.java:9:7 mutastic/keep-operand total / 10 becomes total in Checkout.discount()m2413972b src/main/java/com/example/checkout/Checkout.java:9:7 mutastic/return-value returns 0 instead in Checkout.discount()mee8d2a4d src/main/java/com/example/checkout/Checkout.java:9:20 mutastic/math / becomes * in Checkout.discount()mf8a628eb src/main/java/com/example/checkout/Checkout.java:9:20 mutastic/other-arithmetic / becomes + in Checkout.discount()m95f86040 src/main/java/com/example/checkout/Checkout.java:9:20 mutastic/other-arithmetic / becomes - in Checkout.discount()m51b57889 src/main/java/com/example/checkout/Checkout.java:9:20 mutastic/other-arithmetic / becomes % in Checkout.discount()mb6127f18 src/main/java/com/example/checkout/Checkout.java:11:5 mutastic/constant-value the constant 0 becomes 1 in Checkout.discount()m6410385b src/main/java/com/example/checkout/Checkout.java:11:5 mutastic/constant-value the constant 0 becomes -1 in Checkout.discount()mf4e4c49c src/main/java/com/example/checkout/Checkout.java:11:5 mutastic/return-value returns 1 instead in Checkout.discount()mc86060dc src/main/java/com/example/checkout/Checkout.java:16:5 mutastic/null-parameter receipt is null from the start of the method in Checkout.pay()me11e42ae src/main/java/com/example/checkout/Checkout.java:16:5 mutastic/keep-operand quantity * price becomes quantity in Checkout.pay()mf248f66b src/main/java/com/example/checkout/Checkout.java:16:5 mutastic/keep-operand quantity * price becomes price in Checkout.pay()m21faa923 src/main/java/com/example/checkout/Checkout.java:16:26 mutastic/math * becomes / in Checkout.pay()m55a75e34 src/main/java/com/example/checkout/Checkout.java:16:26 mutastic/other-arithmetic * becomes + in Checkout.pay()m3ab63032 src/main/java/com/example/checkout/Checkout.java:16:26 mutastic/other-arithmetic * becomes - in Checkout.pay()m68b8adfd src/main/java/com/example/checkout/Checkout.java:16:26 mutastic/other-arithmetic * becomes % in Checkout.pay()m23048dc9 src/main/java/com/example/checkout/Checkout.java:17:15 mutastic/omit-call discount() is left out, so what it's given goes on in its place in Checkout.pay()md47a74cb src/main/java/com/example/checkout/Checkout.java:18:13 mutastic/remove-discarded-call the call to add() is removed in Checkout.pay()mee1fc9ef src/main/java/com/example/checkout/Checkout.java:19:5 mutastic/keep-operand total - off becomes total in Checkout.pay()m45d77da9 src/main/java/com/example/checkout/Checkout.java:19:5 mutastic/keep-operand total - off becomes off in Checkout.pay()m6073d12b src/main/java/com/example/checkout/Checkout.java:19:5 mutastic/return-value returns 0 instead in Checkout.pay()m03964b29 src/main/java/com/example/checkout/Checkout.java:19:18 mutastic/math - becomes + in Checkout.pay()m5ba95ca2 src/main/java/com/example/checkout/Checkout.java:19:18 mutastic/other-arithmetic - becomes * in Checkout.pay()mf7012a37 src/main/java/com/example/checkout/Checkout.java:19:18 mutastic/other-arithmetic - becomes / in Checkout.pay()md46482dd src/main/java/com/example/checkout/Checkout.java:19:18 mutastic/other-arithmetic - becomes % in Checkout.pay()estimate: 32 more mutants than defaults, up to 1.0s more of tests, from the run of 28 Nov 2026 23:52 UTC42 mutantsmutastic mutants fixtures/checkout --operators=strongerma7d1f59d src/lib.rs:6:8 mutastic/remove-conditional total >= 100 is always true in discountm0f966c12 src/lib.rs:6:8 mutastic/remove-conditional total >= 100 is always false in discountma4286e9f src/lib.rs:6:14 mutastic/boundary >= becomes > in discountm5d1ed654 src/lib.rs:6:14 mutastic/other-comparison >= becomes < in discountm11accdd0 src/lib.rs:6:14 mutastic/comparison >= becomes == in discountm690ba6b7 src/lib.rs:6:14 mutastic/other-comparison >= becomes <= in discountm0f0e5084 src/lib.rs:6:14 mutastic/other-comparison >= becomes != in discountme72201ca src/lib.rs:6:17 mutastic/constant-value 100 becomes 101 in discountm5c8c3354 src/lib.rs:6:17 mutastic/constant-value 100 becomes 99 in discountm6be83c47 src/lib.rs:6:17 mutastic/constant-value 100 becomes 0 in discountm1b68d277 src/lib.rs:6:17 mutastic/constant-value 100 becomes 1 in discountm6061aa93 src/lib.rs:7:16 mutastic/return-value returns 0 instead in discountmdece90bd src/lib.rs:7:16 mutastic/keep-operand total / 10 becomes total in discountmf4c6bfb8 src/lib.rs:7:22 mutastic/math / becomes * in discountmacebcc29 src/lib.rs:7:22 mutastic/other-arithmetic / becomes + in discountm5c7b95a4 src/lib.rs:7:22 mutastic/other-arithmetic / becomes - in discountmf2ae8a59 src/lib.rs:7:22 mutastic/other-arithmetic / becomes % in discountm0081b732 src/lib.rs:7:24 mutastic/constant-value 10 becomes 11 in discountmc7fcffe2 src/lib.rs:7:24 mutastic/constant-value 10 becomes 9 in discountm9103d5c4 src/lib.rs:7:24 mutastic/constant-value 10 becomes 0 in discountm668fb60f src/lib.rs:7:24 mutastic/constant-value 10 becomes 1 in discountm669a0afd src/lib.rs:9:5 mutastic/return-value returns 1 instead in discountmf0c43a93 src/lib.rs:14:17 mutastic/keep-operand quantity * price becomes quantity in paymd6d95190 src/lib.rs:14:17 mutastic/keep-operand quantity * price becomes price in paym3590a884 src/lib.rs:14:26 mutastic/math * becomes / in paym29b08789 src/lib.rs:14:26 mutastic/other-arithmetic * becomes + in paym3bbb410a src/lib.rs:14:26 mutastic/other-arithmetic * becomes - in payma7d5b2b0 src/lib.rs:14:26 mutastic/other-arithmetic * becomes % in paym784fc10e src/lib.rs:15:15 mutastic/omit-call discount(total) becomes total in payma1e58306 src/lib.rs:16:5 mutastic/remove-void-call receipt.push(format!("discount {off}")); is removed in paymc509a35e src/lib.rs:17:5 mutastic/return-value returns 0 instead in paym2e132563 src/lib.rs:17:5 mutastic/keep-operand total - off becomes total in paym4d187d19 src/lib.rs:17:5 mutastic/keep-operand total - off becomes off in paymee18531c src/lib.rs:17:11 mutastic/math - becomes + in paym515e777e src/lib.rs:17:11 mutastic/other-arithmetic - becomes * in paymbf8a1505 src/lib.rs:17:11 mutastic/other-arithmetic - becomes / in paym1127474d src/lib.rs:17:11 mutastic/other-arithmetic - becomes % in payno estimate: 9 of the 27 more mutants are in code the run of 29 Nov 2026 02:28 UTC didn't measure; add --estimate to measure it all37 mutantsmutastic mutants samples/checkout --operators=strongermea515d6d Sources/Checkout/Checkout.swift:7:8 mutastic/remove-conditional total >= 100 is always false in Checkout.discountm35f672d7 Sources/Checkout/Checkout.swift:7:8 mutastic/remove-conditional total >= 100 is always true in Checkout.discountm43d84c50 Sources/Checkout/Checkout.swift:7:14 mutastic/boundary >= becomes > in Checkout.discountm1e55bbaa Sources/Checkout/Checkout.swift:7:14 mutastic/comparison >= becomes == in Checkout.discountm574c56a3 Sources/Checkout/Checkout.swift:7:14 mutastic/other-comparison >= becomes != in Checkout.discountm4fd20d36 Sources/Checkout/Checkout.swift:7:14 mutastic/other-comparison >= becomes < in Checkout.discountm4acba1ec Sources/Checkout/Checkout.swift:7:14 mutastic/other-comparison >= becomes <= in Checkout.discountmd575608e Sources/Checkout/Checkout.swift:8:14 mutastic/return-value returns 0 instead in Checkout.discountm2157d614 Sources/Checkout/Checkout.swift:8:20 mutastic/other-arithmetic total / 10 becomes total % 10 in Checkout.discountm774ea927 Sources/Checkout/Checkout.swift:8:20 mutastic/other-arithmetic total / 10 becomes total + 10 in Checkout.discountm0de4ee22 Sources/Checkout/Checkout.swift:8:20 mutastic/other-arithmetic total / 10 becomes total - 10 in Checkout.discountmd9aee958 Sources/Checkout/Checkout.swift:8:20 mutastic/math / becomes * in Checkout.discountm654d7ba3 Sources/Checkout/Checkout.swift:10:12 mutastic/return-value returns 1 instead in Checkout.discountmc6a57a33 Sources/Checkout/Checkout.swift:18:26 mutastic/other-arithmetic quantity * price becomes quantity % price in Checkout.paym135d6b09 Sources/Checkout/Checkout.swift:18:26 mutastic/other-arithmetic quantity * price becomes quantity + price in Checkout.paymf0937ac2 Sources/Checkout/Checkout.swift:18:26 mutastic/other-arithmetic quantity * price becomes quantity - price in Checkout.paymeb564ded Sources/Checkout/Checkout.swift:18:26 mutastic/math * becomes / in Checkout.paymfb65b39e Sources/Checkout/Checkout.swift:20:5 mutastic/remove-void-call receipt.append("discount \(off)") is removed in Checkout.paym2f1dc17a Sources/Checkout/Checkout.swift:21:12 mutastic/return-value returns 0 instead in Checkout.paym032e6a8e Sources/Checkout/Checkout.swift:21:18 mutastic/other-arithmetic total - off becomes total % off in Checkout.paym1a4b3e34 Sources/Checkout/Checkout.swift:21:18 mutastic/other-arithmetic total - off becomes total * off in Checkout.paymedda123a Sources/Checkout/Checkout.swift:21:18 mutastic/other-arithmetic total - off becomes total / off in Checkout.paymc3bd87e1 Sources/Checkout/Checkout.swift:21:18 mutastic/math - becomes + in Checkout.payestimate: 13 more mutants than defaults, up to 953ms more of tests, from the run of 1 Dec 2026 23:51 UTC23 mutantsThe line before the count is an estimate, from what the last run’s coverage pass measured: what
the set’s extra mutants would add to the tests’ time, at most, as a caught mutant stops at its
first failing test. Where that run measured nothing, or the code has changed since, it says so
instead of guessing; mutastic mutants --estimate runs every test once, with no mutant in, and
estimates defaults, stronger and all.
With every test so far in, the defaults catch everything. stronger finds one more:
mutastic run samples/checkout --operators=stronger Missed ────────────────────────────────────────────────────────────
❯ src/main/java/com/example/checkout/Checkout.java 1 missed in 1 method
✗ MISSED no test needs quantity in quantity * price in pay() ┌─ src/main/java/com/example/checkout/Checkout.java:16 │ 15 │ public int pay(int quantity, int price, List<String> receipt) { 16 │ int total = quantity * price; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one value kept 17 │ int off = discount(total); │ = mutant - int total = quantity * price; + int total = price; = operator mutastic/keep-operand · https://docs.mutastic.io/java/operators/arithmetic/#keep-operand = note: inputs seen: quantity = 1; price = 50, 99, 100, 250 covered by CheckoutTest#bigOrdersGetADiscount, CheckoutTest#ordersJustUnder100PayFullPrice, CheckoutTest#ordersOf100GetADiscount and 1 more (all 4 covering tests still pass) = help: add a test where quantity changes the result of quantity * price, and assert it
done when mutastic verify mf248f66b samples/checkout passes reproduce mutastic run --only=mf248f66b samples/checkout or ignore mutastic ignore mf248f66b --reason="<why>" samples/checkout
Next: mutastic verify <id> samples/checkout · mutastic run --only=<id> samples/checkout · mutastic explain <id> samples/checkout
Classes 0 clean | 1 with misses Mutants ✓ 41 caught · ✗ 1 missed (42) Worst at Checkout.pay() 1 ✗ Test runs 60 (168 without coverage selection) Start at 03:35:59 Duration 2.1s (setup 0ms, build 527ms, coverage 209ms, mutants 338ms, checking 1.0s, reports 33ms) Tests 4 on JDK 17 · 1 worker Reports samples/checkout/build/mutastic/mutation.json · samples/checkout/build/mutastic/mutation.html Score 97.6% PASS 1 missed, above the threshold of 80. · not compared with the last run, which used other operators (defaults)Every test buys one item, so quantity * price and price are the same on every test: a bug that
drops the quantity would ship. The defaults only try * to /, and the tests catch that one,
since 1 / 250 is 0. A test that buys more than one closes the gap:
@Testvoid severalItemsCostTheirPriceEach() { assertEquals(60, new Checkout().pay(3, 20, new ArrayList<>()));}mutastic verify mf248f66b samples/checkoutmutastic: mf248f66b is caught by com.example.checkout.CheckoutTest#severalItemsCostTheirPriceEachWith every test so far in, the defaults catch everything. stronger finds one more:
mutastic run fixtures/checkout --operators=stronger Missed ────────────────────────────────────────────────────────────
❯ src/lib.rs 1 missed in 1 function
✗ MISSED tests pass even when quantity * price becomes price in pay() ┌─ src/lib.rs:14 │ 13 │ pub fn pay(quantity: u32, price: u32, receipt: &mut Vec<String>) -> u32 { 14 │ let total = quantity * price; │ ^^^^^^^^^^^^^^^^ changed to price 15 │ let off = discount(total); │ = mutant - let total = quantity * price; + let total = price; = operator mutastic/keep-operand · https://docs.mutastic.io/rust/operators/arithmetic/#keep-operand = note: inputs seen: price = 50, 99, 100, 250; quantity = 1 covered by checkout::big_orders_get_a_discount, checkout::orders_just_under_100_pay_full_price, checkout::orders_of_100_get_a_discount and 1 more (all 4 covering tests still pass) = help: use inputs where quantity * price and price differ, and assert what pay() does
done when mutastic verify md6d95190 fixtures/checkout passes reproduce mutastic run --only=md6d95190 fixtures/checkout or ignore mutastic ignore md6d95190 --reason="<why>" fixtures/checkout
Next: mutastic verify <id> fixtures/checkout · mutastic run --only=<id> fixtures/checkout · mutastic explain <id> fixtures/checkout
Files 0 clean | 1 with misses Mutants ✓ 36 caught · ✗ 1 missed (37) Worst at pay() 1 ✗ Build one build of every mutant, 2 rounds (check and build) Test runs 126 (148 without coverage selection) Start at 09:44:20 Duration 4.9s (setup 1.2s, build 3.0s, coverage 302ms, mutants 118ms, checking 24ms, reports 9ms) Tests 4 on rustc 1.100.0 · 4 workers Reports fixtures/checkout/target/mutastic/mutation.json · fixtures/checkout/target/mutastic/mutation.html Score 97.3% PASS 1 missed, above the threshold of 80. · not compared with the last run, which used other operators (defaults)Every test buys one item, so quantity * price and price are the same on every test: a bug that
drops the quantity would ship. The defaults only try * to /, and the tests catch that one,
since 1 / 250 is 0. A test that buys more than one closes the gap:
#[test]fn several_items_cost_their_price_each() { assert_eq!(pay(3, 20, &mut Vec::new()), 60);}mutastic verify md6d95190 fixtures/checkoutmutastic: md6d95190 is caught by checkout::several_items_cost_their_price_eachWith every test so far in, the defaults catch everything, and so does stronger:
mutastic run samples/checkout --operators=stronger Files 1 clean Mutants ✓ 23 caught (23) Build one build of every mutant, 1 round (build) Test runs 80 (92 without coverage selection) Start at 22:29:17 Duration 1.2s (setup 29ms, build 844ms, coverage 23ms, mutants 221ms, reports 25ms) Tests 4 on swift 6.3.3 · 4 workers Reports samples/checkout/.build/mutastic/mutation.json · samples/checkout/.build/mutastic/mutation.html Score 100.0% PASS Every mutant was caught. · not compared with the last run, which used other operators (defaults)The Java and Rust editions’ stronger sets each find one more here, a mutant that keeps only one
side of quantity * price: every test buys one item, so price alone gives the same total. The
Swift edition makes no such mutant yet, so a test that buys more than one is still worth writing.
Which to use
Section titled “Which to use”- Coverage finds what no test runs. That’s worth knowing, and cheap to measure. mutastic lists
it too, under
Not covered. - A coverage gate says the tests ran the code. mutastic’s score says they checked it. A score can’t be raised by calling code without checking it, which a coverage number can.
- The defaults first,
strongerwhen they’re all caught. It finds gaps like the one above, at the cost of more mutants to run.
Writing tests first doesn’t close these gaps by itself: Working test-first shows a test written first passing on code that’s wrong, and mutastic finding it in the cycle.