mutant
Mutation testing for Flutter and Dart packages. mutant makes small, deliberate bugs in
your code — < becomes <=, a call disappears, true turns into false — runs your tests against
each one and tells you which ones no test noticed. Those are the places where a real regression
would sail through CI.
Coverage tells you which lines ran. Mutation testing tells you whether your tests would catch a
change to them. That matters more than ever when an AI writes both the code and the tests: a test
that only restates what the code does passes coverage, and fails here.
$ mutant run --diff origin/main
Mutation score: 81.8% (killed 18, timeout 0, survived 4, no coverage 0, no tests 0) in 13s
Surviving mutants:
lib/cart.dart:23 >= → > [3b9c80943a]
lib/cart.dart:23 100 → 101 [9676a0b1c8]
An order of exactly 100 gets no test: nothing pins the discount boundary.
Features
- Flutter-native. Runs
flutter test — unit, widget and golden tests.
- Golden tests are first-class. Kills by goldens are reported separately; UI mutants (remove a
child, empty a
Text, zero a padding) are only made where goldens can see them; when goldens fail
on clean code because of pixel differences between machines, they are re-baselined for the run and
restored afterwards. Your golden files are never changed.
- Fast. All mutants are compiled in once (mutation schemata) and switched at runtime; each mutant
runs only against the test files that actually execute it; with
--diff, only the lines you
changed are mutated.
- Type-aware. Mutants come from the Dart analyzer, so they compile — no wasted runs on syntax
noise.
- Safe. Sources are restored and hash-checked after every run, also on Ctrl+C;
mutant restore undoes an interrupted one.
- CI-ready. A GitHub Action with annotations on the PR diff, a job summary, a score threshold
and outputs.
- Agent-ready. Ships an Agent Skill for Claude Code, Codex, Cursor and
Copilot that triages survivors, writes the missing tests and re-verifies them with the CLI.
Install
Preview. mutant is not on pub.dev yet. Install it from GitHub:
dart pub global activate --source git https://github.com/dmkasperski/mutant
Once it is published: dart pub global activate mutant.
This needs Dart ≥ 3.13 (Flutter ≥ 3.47) to run the tool. Your project can be on an older Flutter:
the tool runs your tests with your project's own Flutter. If your dart is older, build it with any
Dart ≥ 3.13 (dart compile exe bin/mutant.dart -o mutant) and put the binary on your PATH, or
use the GitHub Action, which builds the tool itself.
Linux and macOS are supported. Windows is not (yet).
Usage
Run from the package root (the directory with pubspec.yaml):
| What | Command |
|---|
| Lines changed on your branch | mutant run --diff $(git merge-base HEAD origin/main) |
| Uncommitted changes | mutant run --diff HEAD |
| Some files | mutant run --files lib/cart.dart |
| The whole package (an audit) | mutant run --all |
| List mutants without running | mutant run --all --dry-run |
| Re-check mutants after adding tests | mutant run --all --only 3b9c80943a --only 9676a0b1c8 |
| Fail below a score | mutant run --diff origin/main --threshold 80 |
A library whose example/ app tests it too | mutant run --all --test-package example |
The project's Flutter is used for tests: fvm is detected; anything else via
--flutter "<command>". mutant --help lists every option.
Don't edit the package while a run is in progress — mutants are written into lib/ in place
and restored at the end.
Reading the result
| Status | Meaning |
|---|
killed / timeout | A test failed or hung with the mutant — the tests caught it. |
survived | Tests ran that code and still passed. A bug in your tests. |
noCoverage | No test executes that code. |
noTests | No test file imports that file at all. |
invalid | The mutant does not compile; not counted. |
Score = (killed + timeout) / (killed + timeout + survived + no coverage).
The full JSON report (one entry per mutant, which test killed it, timings) is written to
.dart_tool/mutant/reports/ — or --report-dir.
Ignoring code
log.fine('cache miss'); // mutant:ignore
// mutant:ignore on the line or the line above; // mutant:ignore-file anywhere in a file.
Generated files (*.g.dart, *.freezed.dart, …), toString, hashCode, debugFillProperties,
dispose, asserts, logging calls and debugLabel arguments are skipped automatically. More:
--exclude <regex>.
GitHub Actions
on: pull_request