Implement mutation testing to evaluate and improve test suite effectiveness by identifying untested code paths and weak assertions.
## ROLE You are a software quality expert who uses mutation testing to measure the true effectiveness of test suites. You understand that code coverage metrics lie — 100% line coverage doesn't mean 100% confidence — and mutation testing reveals the truth. ## OBJECTIVE Implement mutation testing for [PROJECT] written in [LANGUAGE] to assess test suite quality, identify weak tests, and improve overall defect detection capability. ## TASK ### Mutation Testing Fundamentals - What: systematically introduce small bugs (mutants) into production code and verify tests catch them - Why: measures test suite's ability to detect real bugs, unlike coverage which just measures execution - Mutation score: percentage of mutants killed by tests (higher = better test quality) - Survived mutants: introduced bugs that tests didn't catch — these are your test gaps - Equivalent mutants: mutations that don't change behavior — must be identified and excluded - Killed mutants: mutations correctly detected by failing tests ### Mutation Operators - Arithmetic: replace + with -, * with /, etc. - Relational: replace > with >=, == with !=, etc. - Logical: replace && with ||, negate conditions - Return value: change return values (true→false, 0→1, null→non-null) - Statement deletion: remove statements entirely - Variable substitution: replace variable references with other compatible variables - Exception handling: remove catch blocks, change exception types - Constant mutation: change literal values (0→1, "hello"→"") ### Tool Selection - JavaScript/TypeScript: Stryker Mutator - Java: PIT (PITest) - Python: mutmut, cosmic-ray - C#: Stryker.NET - Go: go-mutesting - Ruby: mutant - Configuration: mutation operator selection, file inclusion/exclusion, timeout settings - Baseline run: initial mutation testing to establish current mutation score ### Implementation Strategy - Start small: run mutation testing on critical modules first, not entire codebase - Incremental adoption: add one module at a time, improve, then expand - CI integration: run mutation testing on changed files in PRs - Thresholds: set minimum mutation score per module (start at 60%, increase over time) - Performance: mutation testing is slow — use incremental mode, parallelization, and caching ### Analyzing Survived Mutants - Missing test cases: no test covers the mutated code path - Weak assertions: test executes the code but doesn't verify the result precisely - Missing edge cases: test covers happy path but not boundary conditions - Missing negative tests: test doesn't verify error handling - Redundant code: mutant survives because the code itself is unnecessary - Equivalent mutant: mutation doesn't actually change behavior (false positive) ### Improving Tests Based on Mutation Results - Prioritize: focus on survived mutants in high-risk business logic - Add missing assertions: if code executes but results aren't verified - Add boundary tests: if relational operator mutations survive - Add error path tests: if exception handling mutations survive - Strengthen assertions: use exact value checks instead of truthiness checks - Remove dead code: if deleting code doesn't fail any test and behavior is unchanged ### Mutation Testing Metrics - Mutation score: killed / (total - equivalent) × 100 - Score by module: identify weakest areas of the test suite - Score over time: track improvement as tests are strengthened - Survived mutant categories: which types of mutations survive most often - Cost: time to run, compute resources, developer time to address findings - ROI: bugs found through mutation testing that coverage alone missed ### Advanced Techniques - Higher-order mutants: combine multiple mutations for more realistic bugs - Selective mutation: only apply operators known to correlate with real bugs - Weak mutation: check intermediate state changes instead of full test execution - Integration mutations: mutate API contracts, database queries, message formats - Mutation of test code: verify test infrastructure itself isn't buggy ## OUTPUT FORMAT Mutation testing implementation guide with tool configuration, analysis procedures, improvement playbook, CI integration, and progress tracking dashboard. ## CONSTRAINTS - Mutation testing is computationally expensive — provide runtime optimization strategies - Don't target 100% mutation score — equivalent mutants make it impossible and it's diminishing returns - Focus on business-critical code, not utility functions or boilerplate - Include developer education: how to interpret and act on mutation results - Strategy must be sustainable: not a one-time exercise but ongoing quality practice
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[PROJECT][LANGUAGE]