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.
What arid means
Section titled “What arid means”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 savedvar lines = new ArrayList<>(orders.size() * 2); // * becomes /: the list still grows as it needs toThread.sleep(100); // removed: the same work, soonerinfo!("saved order {id}"); // removed: the order is still savedconfig.unwrap(); // removed: the same work, without the check that config is there// Removed: the order is still saved.print("saved order \(id + 1)")// * becomes /: the array still grows as it needs to.out.reserveCapacity(names.count * 2)// - becomes +: only a failed check's message changes.precondition(sum >= 0, "a total of \(sum - 1)")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.
Why skip them
Section titled “Why skip them”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.
How mutastic decides
Section titled “How mutastic decides”- 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, aThread.sleep, the constructor of one of the JDK’s collections. A method calledlogor a variable calledtimeoutis nothing special. In the Rust edition, a rule matches the syntax: an output macro such asinfo!used as a statement, or a value aletworks 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
ArrayListis 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, andmutastic explainshows 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.
What is never arid
Section titled “What is never arid”Some code looks like plumbing and decides what the program does. mutastic counts it:
- Starting work, and waiting for it: a removed
start(),submit()orjoin(), with a time limit or without, and in Rust a removedhandle.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’sunlock(). - Time limits that decide what happens: a timeout given to
Future.getorCountDownLatch.awaitor a timedjoin(), 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.
What it can cost
Section titled “What it can cost”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.
Check what the skips hide
Section titled “Check what the skips hide”MUTASTIC_ARID=audit runs every arid mutant anyway, for one run, without changing what counts:
MUTASTIC_ARID=audit mutastic run samples/salesThe 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:
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.
Set MUTASTIC_ARID=audit for one run, and mutastic runs every mutant its arid rules skip, then
says what became of them. They still stay out of the score:
MUTASTIC_ARID=audit mutastic run fixtures/aridThe summary gains the same Arid audit row. With no failure origin in this edition yet, a catch
counts as by an assertion when the failing test’s panic is a failed assert! or assert_eq!.
Set MUTASTIC_ARID=audit for one run, and mutastic runs every mutant its arid rules skip, then
says what became of them. They still stay out of the score:
MUTASTIC_ARID=audit mutastic run samples/arid --operators=all Mutants ✓ 13 caught · ✗ 6 missed · 20 skipped (20 arid) (39) Arid audit 20 ran anyway: 4 caught (0 by an assertion), 16 missed, 0 not coveredA catch counts as by an assertion when the failing test’s failure is a failed #expect or
#require, an Issue.record, or an XCTest assertion. Here the 4 caught are the C results rule’s:
each changes the check of pthread_mutex_init’s result so it fails, and the code calls
fatalError. A crash like that says nothing either way, and the 16 missed mean the rules are doing
their job.
Bring a rule back
Section titled “Bring a rule back”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 itmutastic 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.
A mutate: rule in mutastic.yaml brings back the arid skips in the code it covers: the rules
its arid: names, by the ids the Java edition uses, or every rule without it. The Rust edition has
no annotations, so the rule is the only way:
rules: - mutate: crate::report::Summary::of arid: [mutastic:output] reason: the summary is printed for people to read, and the tests check itmutastic explain on a skipped mutant names its rule, links to its section of Arid
rules and prints the rule to copy.
The Rust edition never changes what’s inside a macro’s arguments. So the biggest kinds of arid code
in Java, log lines, println! and format! text, the messages of assert!, panic! and expect,
and debug_assert!, never produce a mutant in Rust, and need no rule. The rules it does have, as
they ship, are in Arid rules, with what each edition does for every rule.
A mutate: rule in mutastic.yaml brings back the arid skips in the code it covers, a type or one
function: the rules its arid: names, by the ids every edition uses, or every rule without it. The
Swift edition has no annotations, so the rule is the only way:
rules: - mutate: Orders.save arid: [mutastic:output] reason: the audit tool reads these linesmutastic explain on a skipped mutant names its rule, links to its section of Arid
rules and prints the rule to copy. The Swift edition’s rules, and what it does
for every other rule, are in Arid rules.