Mutation Testing
ELI5 — The Vibe Check
Mutation testing is a way to test your tests. A tool secretly changes (mutates) your code — like flipping a > to >= or removing a return — and checks if your tests catch it. If your tests don't notice the code changed, your tests are weak. Devious but brilliant.
Real Talk
Mutation testing evaluates test quality by introducing small code changes (mutants) and checking whether tests catch them. A surviving mutant means tests are missing coverage. Tools like Stryker (JS) or PIT (Java) generate mutants and report a mutation score (percentage killed).
Show Me The Code
// Original code
function isAdult(age) { return age >= 18; }
// Mutant generated:
function isAdult(age) { return age > 18; } // changed >= to >
// If your tests don't catch this, they're weak!
// A test with age=18 would catch it.
When You'll Hear This
"Our mutation score is only 40% — we need better tests, not just more coverage." / "Mutation testing found that our age validation tests didn't cover the boundary value."
Related Terms
Code Coverage
Code coverage is the report card for your tests. It shows you a map of your code and highlights which lines got tested (green) and which didn't (red).
Coverage
Coverage tells you what percentage of your code is actually tested. 80% coverage means 80% of your lines are touched by at least one test.
Property-Based Testing
Instead of writing specific test cases (add(2,3)=5), property-based testing generates thousands of random inputs automatically and checks that certain prop...
Unit Test
A unit test is like checking that one single LEGO brick isn't broken before you use it in your big castle.