| name | mutation-testing |
| description | Guide developers through mutation testing to assess and improve test suite quality |
| license | Complete terms in LICENSE.txt |
Mutation Testing
Version: v0.18.0
When to Use
- Assessing test suite quality beyond coverage
- Identifying weak test coverage
- Evaluating test meaningfulness
- Improving test effectiveness
Core Concept
- Mutate: Make small code changes
- Test: Run test suite against mutated code
- Evaluate: Check if tests detect (kill) mutations
Key Terms
- Mutant: Modified code with one change
- Killed: Test detected mutation (good)
- Survived: Test missed mutation (bad)
- Equivalent: Mutation behaves identically (can't kill)
- Mutation Score: killed / (total - equivalent)
Mutation Operators
Arithmetic
| Original | Mutated |
|---|---|
+ |
- |
* |
/ |
Relational
| Original | Mutated |
|---|---|
< |
<= |
== |
!= |
> |
>= |
Logical
| Original | Mutated |
|---|---|
and |
or |
not |
(removed) |
Constants
| Original | Mutated |
|---|---|
0 |
1 |
true |
false |
Score Interpretation
| Score | Quality |
|---|---|
| 90-100% | Excellent |
| 75-89% | Good |
| 60-74% | Acceptable |
| <60% | Weak |
Context matters: High-risk code (payment, auth) should target 90%+
Analyzing Survivors
- Review the mutant code change
- Understand what behavior changed
- Decide: Add test, mark equivalent, or accept risk
Common survival patterns:
- Missing boundary tests
- Missing error case tests
- Missing assertions on return values
Framework Examples
Python (mutmut):
pip install mutmut
mutmut run
mutmut results
JavaScript (Stryker):
npm install @stryker-mutator/core
npx stryker init
npx stryker run
Java (PIT):
mvn org.pitest:pitest-maven:mutationCoverage
Best Practices
- Start small (critical modules first)
- Set realistic goals (not 100%)
- Address survivors systematically
- Integrate with CI (limited scope on PRs)
- Balance cost vs value
Common Pitfalls
- Running on everything (too slow)
- Ignoring equivalent mutants
- Adding tests without understanding
- Over-testing to kill mutants
End of Mutation Testing Skill