mutation-testing
Uses mutation testing to find weak or missing tests that fail to detect bugs.
Install
mkdir -p .claude/skills/mutation-testing-chloebrett && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/19096" && unzip -o skill.zip -d .claude/skills/mutation-testing-chloebrett && rm skill.zipInstalls to .claude/skills/mutation-testing-chloebrett
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Mutation testing patterns for verifying test effectiveness. Use when analyzing branch code to find weak or missing tests.Key capabilities
- →Generate small bugs in production code
- →Execute test suite against mutated code
- →Evaluate if tests fail against mutants
- →Identify tests that do not catch changes
- →Produce a summary report of mutation testing
How it works
The skill introduces small, controlled errors into the production code and then runs the existing test suite against these altered versions. It determines test effectiveness by observing whether the tests fail (kill the mutant) or pass (the mutant survives).
Inputs & outputs
When to use mutation-testing
- →Verifying test effectiveness
- →Identifying weak test cases
- →Validating refactoring safety
About this skill
Mutation Testing
For writing good tests (factories, behavior-driven patterns), load the testing skill. This skill focuses on verifying test effectiveness.
Mutation testing answers the question: "Are my tests actually catching bugs?"
Code coverage tells you what code your tests execute. Mutation testing tells you if your tests would detect changes to that code. A test suite with 100% coverage can still miss 40% of potential bugs.
Core Concept
The Mutation Testing Process:
- Generate mutants: Introduce small bugs (mutations) into production code
- Run tests: Execute your test suite against each mutant
- Evaluate results: If tests fail, the mutant is "killed" (good). If tests pass, the mutant "survived" (bad - your tests missed the bug)
The Insight: A surviving mutant represents a bug your tests wouldn't catch.
When to Use This Skill
Use mutation testing analysis when:
- Reviewing code changes on a branch
- Verifying test effectiveness after TDD
- Identifying weak tests that appear to have coverage
- Finding missing edge case tests
- Validating that refactoring didn't weaken test suite
Integration with TDD:
RED-GREEN-MUTATE-REFACTOR Cycle
┌─────────────────────────────────────────────────┐
│ 1. RED: Write failing test │
│ 2. GREEN: Minimum code to pass │
│ 3. MUTATE: Verify tests catch real bugs ◄── │ ← You are here
│ 4. REFACTOR: Improve structure with confidence │
└─────────────────────────────────────────────────┘
Why MUTATE before REFACTOR: Mutation testing validates test strength before you restructure code. Refactoring with unverified tests means restructuring code whose safety net you haven't checked.
Execution Process
When verifying test effectiveness, actually mutate the code and run the tests. Do not just reason about whether tests would catch mutations — prove it.
Step 1: Identify Changed Code
# Get files changed on the branch
git diff main...HEAD --name-only | grep -E '\.(ts|js|tsx|jsx)$' | grep -v '\.test\.'
# Get detailed diff for analysis
git diff main...HEAD -- src/
Step 2: Apply Mutations and Run Tests
For each changed function/method, work through the mutation operators (see Mutation Operators section below). For each applicable mutation:
- Mutate: Change the production code (e.g., flip
*to/, negate a condition) - Run: Execute the test suite
- Evaluate: Did a test fail?
- Yes → mutant killed (good). Revert the mutation.
- No → mutant survived (bad). Revert the mutation, then add or strengthen a test.
- Revert: Always restore the original code before the next mutation
Always revert each mutation before applying the next. Never leave mutated code in place.
You do not need to apply every possible mutation to every line. Focus on:
- Changed code on the branch
- Operators most likely to have surviving mutants (see Quick Reference)
- Conditions with boundary values
- Boolean logic with multiple operands
Step 3: Produce a Report
After working through the mutations, produce a summary:
## Mutation Testing Report
### Killed (tests caught the mutation)
- `calculateTotal`: `*` → `/` — killed by "calculates total for multiple items"
- `isEligible`: `>=` → `>` — killed by "returns true at exact boundary"
### Survived (tests DID NOT catch the mutation)
- `applyDiscount`: `>` → `>=` — no test for boundary value at exactly 100
→ **Action**: Add boundary test for discount threshold
### Summary
- Mutations applied: 8
- Killed: 6
- Survived: 2
- Mutation score: 75%
Step 4: Kill Surviving Mutants
Not every surviving mutant warrants a new test. Some mutations produce equivalent behavior, and some boundary cases are low-risk enough that the test would add noise without meaningful protection.
Fix immediately when:
- The mutation represents a realistic bug (wrong operator, inverted condition)
- The surviving mutant is in critical business logic (money, permissions, eligibility)
- The fix is a simple boundary test or stronger assertion
Ask the human when:
- You're unsure whether the mutation represents a real risk
- The test to kill it would be complex or hard to name clearly
- The mutation is in a code path that's also covered by integration/E2E tests
- The surviving mutant feels like an equivalent mutant but you're not certain
Present the mutation, explain why the current tests don't catch it, and let the human decide whether it's worth a new test.
When fixing, follow TDD — write the failing test first, verify it fails against the mutated code, then verify it passes against the original code.
Mutation Operators
Arithmetic Operator Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
a + b | a - b | Addition behavior |
a - b | a + b | Subtraction behavior |
a * b | a / b | Multiplication behavior |
a / b | a * b | Division behavior |
a % b | a * b | Modulo behavior |
Example Analysis:
// Production code
const calculateTotal = (price: number, quantity: number): number => {
return price * quantity;
};
// Mutant: price / quantity
// Question: Would tests fail if * became /?
// ❌ WEAK TEST - Would NOT catch mutant
it('calculates total', () => {
expect(calculateTotal(10, 1)).toBe(10); // 10 * 1 = 10, 10 / 1 = 10 (SAME!)
});
// ✅ STRONG TEST - Would catch mutant
it('calculates total', () => {
expect(calculateTotal(10, 3)).toBe(30); // 10 * 3 = 30, 10 / 3 = 3.33 (DIFFERENT!)
});
Conditional Expression Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
a < b | a <= b | Boundary value at equality |
a < b | a >= b | Both sides of condition |
a <= b | a < b | Boundary value at equality |
a <= b | a > b | Both sides of condition |
a > b | a >= b | Boundary value at equality |
a > b | a <= b | Both sides of condition |
a >= b | a > b | Boundary value at equality |
a >= b | a < b | Both sides of condition |
Example Analysis:
// Production code
const isAdult = (age: number): boolean => {
return age >= 18;
};
// Mutant: age > 18
// Question: Would tests fail if >= became >?
// ❌ WEAK TEST - Would NOT catch boundary mutant
it('returns true for adults', () => {
expect(isAdult(25)).toBe(true); // 25 >= 18 = true, 25 > 18 = true (SAME!)
});
// ✅ STRONG TEST - Would catch boundary mutant
it('returns true for exactly 18', () => {
expect(isAdult(18)).toBe(true); // 18 >= 18 = true, 18 > 18 = false (DIFFERENT!)
});
Equality Operator Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
a === b | a !== b | Both equal and not equal cases |
a !== b | a === b | Both equal and not equal cases |
a == b | a != b | Both equal and not equal cases |
a != b | a == b | Both equal and not equal cases |
Logical Operator Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
a && b | a || b | Case where one is true, other is false |
a || b | a && b | Case where one is true, other is false |
a ?? b | a && b | Nullish coalescing behavior |
Example Analysis:
// Production code
const canAccess = (isAdmin: boolean, isOwner: boolean): boolean => {
return isAdmin || isOwner;
};
// Mutant: isAdmin && isOwner
// Question: Would tests fail if || became &&?
// ❌ WEAK TEST - Would NOT catch mutant
it('returns true when both conditions met', () => {
expect(canAccess(true, true)).toBe(true); // true || true = true && true (SAME!)
});
// ✅ STRONG TEST - Would catch mutant
it('returns true when only admin', () => {
expect(canAccess(true, false)).toBe(true); // true || false = true, true && false = false (DIFFERENT!)
});
Boolean Literal Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
true | false | Both true and false outcomes |
false | true | Both true and false outcomes |
!(a) | a | Negation is necessary |
Block Statement Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
{ code } | { } | Side effects of the block |
Example Analysis:
// Production code
const processOrder = (order: Order): void => {
validateOrder(order);
saveOrder(order);
sendConfirmation(order);
};
// Mutant: Empty function body
// Question: Would tests fail if all statements removed?
// ❌ WEAK TEST - Would NOT catch mutant
it('processes order without error', () => {
expect(() => processOrder(order)).not.toThrow(); // Empty function also doesn't throw!
});
// ✅ STRONG TEST - Would catch mutant
it('saves order to database', () => {
processOrder(order);
expect(mockDatabase.save).toHaveBeenCalledWith(order);
});
String Literal Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
"text" | "" | Non-empty string behavior |
"" | "Stryker was here!" | Empty string behavior |
Array Declaration Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
[1, 2, 3] | [] | Non-empty array behavior |
new Array(1, 2) | new Array() | Array contents matter |
Unary Operator Mutations
| Original | Mutated | Test Should Verify |
|---|---|---|
+a | -a | Sign matters |
-a | +a | Sign matters |
++a | --a | Increment vs decrement |
a++ | a-- | Increment vs decrement |
Method / Iterator Mutations (Rust)
| Original | Mutated | Test Should Verify |
|---|---|---|
.starts_with() | .ends_with() | Correct string position |
.ends_with() | .starts_with() | Correct string |
Content truncated.
When not to use it
- →When only code coverage metrics are needed
- →When tests are not yet written or are incomplete
- →When the goal is to write new tests from scratch
Limitations
- →Not every surviving mutant requires a new test
- →Some mutations may produce equivalent behavior
- →Focus is on changed code, not every line
How it compares
This approach actively verifies test suite reliable by simulating bugs, unlike passive code coverage which only measures execution paths.
Compared to similar skills
mutation-testing side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| mutation-testing (this skill) | 0 | 2mo | Review | Intermediate |
| python-testing-patterns | 77 | 2mo | Review | Intermediate |
| dependency-upgrade | 26 | 4mo | Review | Intermediate |
| test-cases | 57 | 6mo | No flags | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by chloebrett
View all by chloebrett →You might also like
python-testing-patterns
wshobson
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.
dependency-upgrade
wshobson
Manage major dependency version upgrades with compatibility analysis, staged rollout, and comprehensive testing. Use when upgrading framework versions, updating major dependencies, or managing breaking changes in libraries.
test-cases
cexll
This skill should be used when generating comprehensive test cases from PRD documents or user requirements. Triggers when users request test case generation, QA planning, test scenario creation, or need structured test documentation. Produces detailed test cases covering functional, edge case, error handling, and state transition scenarios.
reviewing-code
CaptainCrouton89
Systematically evaluate code changes for security, correctness, performance, and spec alignment. Use when reviewing PRs, assessing code quality, or verifying implementation against requirements.
wcag-audit-patterns
wshobson
Conduct WCAG 2.2 accessibility audits with automated testing, manual verification, and remediation guidance. Use when auditing websites for accessibility, fixing WCAG violations, or implementing accessible design patterns.
code-coverage-with-gcov
gadievron
Add gcov code coverage instrumentation to C/C++ projects