Set up mutation testing to verify your tests actually catch bugs. Stryker mutates your code and checks if tests fail — the ultimate test quality metric.
## Task Set up mutation testing with Stryker to measure real test effectiveness. ## Requirements - Framework: StrykerJS - Test runner: Vitest or Jest - Language: TypeScript ## Configuration ```typescript // stryker.config.mts export default { mutate: [ "src/**/*.ts", "!src/**/*.test.ts", "!src/**/*.d.ts", "!src/types/**", ], testRunner: "vitest", reporters: ["html", "clear-text", "progress"], thresholds: { high: 80, // Green: mutation score ≥ 80% low: 60, // Red: mutation score < 60% break: 50, // CI fails if score < 50% }, concurrency: 4, timeoutMS: 10000, }; ``` ## What Stryker Does ``` Original: if (age >= 18) return "adult"; Mutant 1: if (age > 18) return "adult"; // Changed >= to > Mutant 2: if (age <= 18) return "adult"; // Changed >= to <= Mutant 3: if (age >= 18) return ""; // Changed string literal Mutant 4: if (true) return "adult"; // Removed condition If your tests STILL PASS with a mutant → your tests have a gap! A "killed" mutant means your tests caught the change. Good. A "survived" mutant means your tests missed it. Bad. ``` ## Implementation Notes 1. Start with critical business logic (payments, auth, calculations) 2. Mutation score > line coverage — it measures test QUALITY not quantity 3. Incremental mode: only test mutants in changed files (CI-friendly) 4. Ignore trivial mutations: log messages, comments, type assertions 5. CI integration: run on PRs, fail if mutation score drops below threshold 6. Report survived mutants as "test improvement opportunities"
No gallery images yet.