Skip to content
mutastic

Arid mutants

Remove a log line and every test still passes. A run that calls that a gap is asking for a test nobody wants: one that reads a log message, breaks the day someone rewords it, and proves nothing about what the code does. A report full of those costs the time it takes to read, and teaches people, and coding agents, to stop trusting the rest of it, which is where the real gaps are.

So mutastic skips mutants like that on its own, as arid. This page says what that means, why it’s a fair line to draw, what it can cost, and how to check it and move it for your code. Each rule, with the setting that brings it back, has its own section in Arid rules.

Code is arid when a test could check it but shouldn’t have to: a change to it shows only in what the program tells a person, or in how fast it runs, not in what it does.

log.info("saved order {}", id); // removed: the order is still saved
var lines = new ArrayList<>(orders.size() * 2); // * becomes /: the list still grows as it needs to
Thread.sleep(100); // removed: the same work, sooner

Arid isn’t the same as equivalent. An equivalent mutant is a fact: no input tells it apart from the code, so no test can catch it. An arid mutant is a judgement: a test could catch it, and mutastic thinks none should have to. Because it’s a judgement, every rule says what it can hide, and every rule can be brought back where your code needs it.

The idea, and the name, come from Google’s mutation testing, which shows developers the mutants their tests miss while their change is in code review. Its authors found that mutants in “uninteresting statements like logging” cost the people reading them time and attention, and that a test written to catch one wasn’t seen as making the suite any better, so those mutants stayed uncaught. Without rules to leave them out, “users would become frustrated with non-actionable feedback and opt out of the system altogether” (Petrović and Ivanković, ICSE 2018).

The first rules they wrote, for logging, for time and for configuration flags, are credited with lifting the share of mutants developers found worth acting on from about 15% to 80%. When they checked 100 calls the logging rule had skipped, 99 were right to skip, and the last was of marginal use (Petrović, Ivanković, Fraser and Just, IEEE TSE 2021).

The same papers are frank about the cost, and so is this page: a rule “may suppress mutation in relevant nodes as a side-effect”. That’s why mutastic’s rules are narrow, and why each one comes with a way to check it.

  • By the exact code, never by a name. A rule matches what the compiled code does: a call to a logger’s type or to System.out, a Thread.sleep, the constructor of one of the JDK’s collections. A method called log or a variable called timeout is nothing special. In the Rust edition, a rule matches the syntax: an output macro such as info! used as a statement, or a value a let works out only for output macros to read.
  • Only where the value goes nowhere else. Text that goes straight into a log call is arid; the same text returned, stored or compared is counted. Arithmetic that only sizes a new ArrayList is arid; the same arithmetic used as a loop’s bound is counted. A value worked out only for a log line, (System.nanoTime() - start) / 1_000_000, is arid, through a local too, but only when every use of it on every path is the log’s.
  • Skipped, never hidden. An arid mutant is still made, keeps its id, and says why it was skipped, kind first: arid: only waits. The summary counts it (4 skipped (4 arid)), it’s in the report and the events, and mutastic explain shows it. It just isn’t in the score.

The kinds of code each rule covers, with the reason each prints, are listed in Arid rules.

In the Swift edition, a rule matches the syntax too: a call that only writes output (print, dump, NSLog, os_log or a logger’s log method) used as a statement, the message of an assert, a precondition or a fatalError, the room reserveCapacity asks for, and the check that a C call succeeded. Each section of Arid rules says what the Swift edition does with that code.

Some code looks like plumbing and decides what the program does. mutastic counts it:

  • Starting work, and waiting for it: a removed start(), submit() or join(), with a time limit or without, and in Rust a removed handle.join().unwrap();. If no test notices the work never ran, or the code read its result before it finished, that’s a gap worth a test.
  • Stopping work: interrupt(), shutdown(), a lock’s unlock().
  • Time limits that decide what happens: a timeout given to Future.get or CountDownLatch.await or a timed join(), a time worked out for a later retry, how many times to retry. Only how long a sleep waits, and how long a pool’s idle threads live, are arid.
  • How work is run: whether a thread is a daemon, a pool’s core or fixed size, a queue’s capacity. A thread’s name, its priority and its stack size are arid: they change how threads look or what they cost, not whether, when or how often work runs.
  • What the code returns, stores or compares, however it got there.
  • A value a log line uses, and something else too. An elapsed time that’s logged and also recorded as a metric, compared with a limit or returned keeps its mutants: one of its uses is behaviour. Arid rules in practice shows what to do when nobody tests that other use.

Every rule is right for most code and wrong for some. A log line can be the product: an audit log, a command’s output. A toString() can be what a customer reads. A sleep can be the backoff that keeps the code from flooding a service. For code like that, the skip hides a real gap.

So each rule’s section in Arid rules says, under What it can hide, the bug it could hide, found by running its mutants against tests that check that behaviour, and When to bring it back. Read those for the rules your code meets.

MUTASTIC_ARID=audit runs every arid mutant anyway, for one run, without changing what counts:

Terminal window
MUTASTIC_ARID=audit mutastic run samples/sales

The summary gains an Arid audit row: how many ran, how many your tests caught, how many of those by a test’s own assertion, and where:

Terminal window
Mutants ✓ 10 caught · ✗ 3 missed · 3 skipped (3 arid) (16)
Arid audit 3 ran anyway: 1 caught (1 by an assertion), 2 missed, 0 not covered; checked in Summary.print()
a test checks what they do: to run them, add to mutastic.yaml
rules:
- mutate: com.example.sales.Summary#print
arid: [mutastic:output]
reason: <why a test should check it>

A catch by an assertion means a test already checks what that code does, so for that code the skip may be hiding a contract: look at it, and bring its rule back if so, with the mutate: rule the audit prints. A catch by a crash (an exception the change caused, not a failed check) says nothing either way, and a miss means the rule is doing its job. The audit is the command line’s; the Gradle and Maven plugins don’t run it.

Bring a rule back where your tests already check that kind of behaviour, or where that output is the product: an audit log, a command-line tool’s output, a library whose toString() is part of its API. Say why, as every rule must: the reason is shown with each mutant the rule brings back. If you’re not sure, run the audit first.

A mutate: rule in mutastic.yaml brings back the arid skips in the code it covers, a class or one method: the rules its arid: names, or every rule without it. @DoMutate on a class or method does the same from the code itself, @DoMutate(value = "…", arid = "mutastic:output"):

rules:
- mutate: com.example.sales.Summary#print
arid: [mutastic:output]
reason: the report is what the command prints, and scripts read it

mutastic explain on a skipped mutant prints this rule, filled in for it.

Neither brings back code the compiler wrote, an equivalent mutant, or code @DoNotMutate or a skip: rule skips. Each rule’s section in Arid rules has the setting for that rule, ready to copy. See Configuration for the patterns a rule takes.