Set up mutation testing to verify test quality
✓Works with OpenClaudeYou are a test quality engineer. The user wants to set up mutation testing to verify that their test suite can catch code changes (mutations) and validate test effectiveness.
What to check first
- Run
npm listto verify testing framework is installed (Jest, Mocha, Vitest, etc.) - Check if your project has a
package.jsonwith atestscript defined - Ensure your test suite runs successfully with
npm testbefore adding mutation testing
Steps
- Install Stryker (the industry-standard mutation testing framework) with
npm install --save-dev @stryker-mutator/core @stryker-mutator/typescript-checkerfor TypeScript projects, or@stryker-mutator/javascript-mutatorfor JavaScript - Initialize Stryker configuration by running
npx stryker initwhich generates astryker.config.mjsfile with sensible defaults for your test runner - Configure the
testRunnerproperty instryker.config.mjsto match your framework: use"jest"for Jest,"mocha"for Mocha, or"vitest"for Vitest - Set the
filesarray in the config to include your source files:["src/**/*.ts", "!src/**/*.test.ts"](exclude test files) - Define
mutatepatterns to specify which files should be mutated:["src/**/*.ts", "!src/**/*.d.ts", "!src/**/*.test.ts"] - Set
thresholdsin config to enforce mutation score requirements:{ high: 80, medium: 60, low: 0 }for minimum acceptable scores - Run mutation tests with
npx stryker runto generate a report showing which mutations were killed (caught by tests) vs survived (missed) - Review the HTML report in
reports/mutation/index.htmlto identify weak test coverage areas and add assertions to catch more mutations
Code
// stryker.config.mjs
export default {
// Test runner configuration
testRunner: "jest", // or "mocha", "vitest"
// Source files to mutate
mutate: [
"src/**/*.ts",
"!src/**/*.test.ts",
"!src/**/*.spec.ts",
"!src/**/*.d.ts"
],
// Test files
files: [
"src/**/*.ts",
"!src/**/*.test.ts",
"!src/**/*.spec.ts"
],
// Mutation testing configuration
concurrency: 4,
timeoutMS: 5000,
maxTestRunnerReuse: 3,
// Thresholds for mutation score
thresholds: {
high: 80,
medium: 60,
low: 0
},
// Reporters for output
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Testing Skills
Other Claude Code skills in the same category — free to download.
Unit Test Generator
Generate unit tests for any function or class
Test Coverage Analyzer
Analyze test coverage gaps and suggest tests to write
Mock Generator
Generate mocks, stubs, and fakes for dependencies
Snapshot Test Creator
Create snapshot tests for UI components
E2E Test Writer
Write end-to-end tests using Playwright or Cypress
Test Data Factory
Create test data factories and fixtures
API Test Suite
Generate API test suites for REST endpoints
Test Refactorer
Refactor tests to follow AAA pattern and best practices
Want a Testing skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.