Recipe
Mutation Testing
Mutation testing measures the quality of your test suite by injecting small faults into your source code and verifying that your tests catch them. If a mutant survives, your tests have a gap.
Core Idea
A mutation operator makes a tiny change — flipping a boolean, removing a condition, swapping an operator. The mutated code is called a mutant. Your test suite runs against each mutant. If a test fails, the mutant is killed. If all tests pass, the mutant survived — and you have uncovered a testing blind spot.
Common Operators
- AOR — Arithmetic operator replacement ( + → - , * → / )
- ROR — Relational operator replacement ( > → >= , == → != )
- COR — Conditional operator replacement ( && → || )
- SBR — Statement block removal (delete entire if-body)
Mutation Score
The ratio of killed mutants to total mutants. A score below 80% signals weak tests. Aim for 100% — every surviving mutant represents untested behavior that can ship as a bug.
Quick Start
- Install a mutation runner (Stryker, PIT, mutmut).
- Point it at your source and test directories.
- Run a baseline to generate mutants.
- Inspect survivors — each one is a missing assertion.
- Write the test that kills it, then repeat.
Next: Property-Based Testing →