Explore mutation testing in Scala as a way to evaluate whether tests actually detect behavior changes instead of merely executing code paths.
Mutation testing: A technique that deliberately changes small pieces of production code and checks whether the test suite fails. If the tests still pass, they may not be asserting behavior strongly enough.
Mutation testing is valuable because coverage numbers can be misleading. A line can be executed without the test actually proving anything useful about its behavior.
A mutator might:
> to >=If the test suite does not notice, you have learned something important: the tests may execute the code, but they are not protecting the behavior well.
Mutation testing tends to pay off most in:
These are places where small behavioral changes matter and where weak assertions can otherwise look “covered.”
A surviving mutant does not automatically mean the tests are bad. It can also indicate:
The right reaction is investigation, not blind score chasing.
Treat mutation reports as review input:
An improving mutation score is useful, but it should follow better tests and clearer code, not artificial assertion inflation.
The team optimizes for a number instead of for clearer behavioral protection.
Mutation testing is expensive. It usually works better as a targeted tool on high-value modules than as a default per-save loop.
Some mutations do not change observable behavior in a meaningful way. Chasing them mechanically wastes time.
Use mutation testing on behavior-critical modules where ordinary coverage is not telling you enough. Review surviving mutants for insight, target weak assertions or unclear code, and use the score as a signal rather than as a vanity metric.