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

  1. Install a mutation runner (Stryker, PIT, mutmut).
  2. Point it at your source and test directories.
  3. Run a baseline to generate mutants.
  4. Inspect survivors — each one is a missing assertion.
  5. Write the test that kills it, then repeat.