Testingadvanced
Set up mutation testing to verify test quality
Mutation Testing Setup
Set up mutation testing to verify test quality
Set up mutation testing to verify test quality.
Instructions
- Install Stryker Mutator:
npm install -D @stryker-mutator/core @stryker-mutator/jest-runner @stryker-mutator/typescript-checker
npx stryker init # interactive setup
- Configure stryker.config.mjs:
export default {
mutator: { excludedMutations: [] },
testRunner: 'jest',
checkers: ['typescript'],
reporters: ['html', 'progress'],
coverageAnalysis: 'perTest',
mutate: ['src/**/*.ts', '!src/**/*.test.ts', '!src/**/*.d.ts'],
};
- Run mutation testing:
npx stryker run
-
Interpret results:
- Killed: mutation was caught by a test (good)
- Survived: mutation was NOT caught (you need better tests)
- No coverage: no test covers this code at all
- Timeout: mutation caused an infinite loop (usually killed)
-
For each surviving mutant, write a test that catches it.
Target: mutation score > 80%
Focus on killing mutants in critical business logic — not in boilerplate.