Skip to main content

Mutation Testing

Mutation testing measures the quality of a test suite itself by deliberately introducing small bugs ("mutants") into the code — changing a `+` to a `-`, flipping a boolean — and checking whether the existing tests catch each one. Tests that fail to catch a mutant reveal a gap in coverage that a plain coverage percentage wouldn't show.

Code coverage answers "did any test execute this line"; mutation testing answers the sharper question "would any test actually notice if this line were wrong." A test suite can have 100% code coverage and still pass against dozens of introduced mutants, if its assertions are weak or missing — mutation testing specifically exposes that gap.

The "mutation score" — the percentage of introduced mutants that were caught (killed) by the test suite — is a much stronger quality signal than raw coverage, though it's also computationally expensive, since it requires re-running the full test suite once per mutant.