Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Testingadvanced

Mutation Testing Setup

Share

Set up mutation testing to verify test quality

Works with OpenClaude

You 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 list to verify testing framework is installed (Jest, Mocha, Vitest, etc.)
  • Check if your project has a package.json with a test script defined
  • Ensure your test suite runs successfully with npm test before adding mutation testing

Steps

  1. Install Stryker (the industry-standard mutation testing framework) with npm install --save-dev @stryker-mutator/core @stryker-mutator/typescript-checker for TypeScript projects, or @stryker-mutator/javascript-mutator for JavaScript
  2. Initialize Stryker configuration by running npx stryker init which generates a stryker.config.mjs file with sensible defaults for your test runner
  3. Configure the testRunner property in stryker.config.mjs to match your framework: use "jest" for Jest, "mocha" for Mocha, or "vitest" for Vitest
  4. Set the files array in the config to include your source files: ["src/**/*.ts", "!src/**/*.test.ts"] (exclude test files)
  5. Define mutate patterns to specify which files should be mutated: ["src/**/*.ts", "!src/**/*.d.ts", "!src/**/*.test.ts"]
  6. Set thresholds in config to enforce mutation score requirements: { high: 80, medium: 60, low: 0 } for minimum acceptable scores
  7. Run mutation tests with npx stryker run to generate a report showing which mutations were killed (caught by tests) vs survived (missed)
  8. Review the HTML report in reports/mutation/index.html to 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

Quick Info

CategoryTesting
Difficultyadvanced
Version1.0.0
AuthorClaude Skills Hub
testingmutationquality

Install command:

curl -o ~/.claude/skills/mutation-testing-setup.md https://claude-skills-hub.vercel.app/skills/testing/mutation-testing-setup.md

Related Testing Skills

Other Claude Code skills in the same category — free to download.

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.