Skip to content

Mutation Testing

Spicy — senior dev territoryTesting

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.