CC-301h · Module 2
Mutation Testing
3 min read
Mutation testing answers the question coverage cannot: are your tests actually catching bugs? The concept: a mutation testing tool (Stryker for JS/TS) introduces small changes (mutations) into your source code — swapping > for <, removing a return statement, changing true to false — and runs your test suite. If a test fails, the mutation is "killed" (your tests caught the bug). If all tests pass, the mutation "survived" (your tests missed a potential bug).
Claude Code integrates mutation testing into your quality workflow. Run Stryker, feed the surviving mutations to Claude: "These mutations survived — meaning our tests did not catch them. For each surviving mutation, write a test that would catch it." Claude reads the mutation (e.g., "changed > to >= on line 42"), understands the boundary condition it exploits, and writes a test that validates the exact boundary. This is the highest-quality test generation possible — each test is proven to catch a specific type of bug.
# 1. Run mutation testing
npx stryker run --reporters json
# 2. Extract surviving mutations
jq '.files[].mutants[] | select(.status == "Survived")' \
reports/mutation/mutation.json > surviving.json
# 3. Feed to Claude
# "These mutations survived. Write tests to kill each one."