Skip to content
Back to skills

Mutation Testing

ASecurity

Mutation testing — code mutations to measure test suite quality.

  • 6 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 6, 2026
developmentjavascripttypescriptpythonjavarubyphpkotlintestinggitdatabase

Works with

  • cli

Security analysis

A100/100

Scanned September 6, 2026

npx -y skills add Dev-Toolbelt/dev-team-agents --skill mutation-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mutation Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Mutation Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/dev-toolbelt-mutation-testing/badge)](https://www.skillsdirectory.com/skills/dev-toolbelt-mutation-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: mutation-testing
description: Mutation testing — code mutations to measure test suite quality.
---

## What It Measures

Code coverage tells you which lines were *executed*. Mutation testing tells you whether your tests actually *catch bugs*.

A **mutant** is a small, automated change to the production code (e.g., `>` → `>=`). If your test suite still passes after that change, the mutant **survived** — meaning no test would catch that bug in real code.

**Mutation score** = (mutants killed / total mutants) × 100

---

## Tools by Language

| Language | Tool | Notes |
|---|---|---|
| JavaScript / TypeScript | [Stryker](https://stryker-mutator.io/) | Supports Jest, Vitest, Jasmine, Mocha |
| Java / Kotlin | [PITest](https://pitest.org/) | Maven + Gradle plugins; fast incremental mode |
| Python | [Mutmut](https://github.com/boxed/mutmut) | Simple CLI; integrates with pytest |
| PHP | [Infection](https://infection.github.io/) | PHPUnit + Pest; mutation badge support |
| Ruby | [Mutant](https://github.com/mbj/mutant) | Supports RSpec; strict coverage mode |

---

## Mutation Score Targets

| Score | Interpretation | Action |
|---|---|---|
| ≥ 80% | Healthy test suite | Maintain; review survivors in critical paths |
| 60–79% | Acceptable; room to improve | Identify weakest modules; add targeted assertions |
| < 60% | Weak assertions throughout | Significant test quality problem; prioritize fixes |

A high line-coverage score with a low mutation score is a red flag — tests are running the code but not asserting the outcomes.

---

## Common Mutant Types

| Mutant | Example | What it reveals |
|---|---|---|
| Arithmetic operator swap | `a + b` → `a - b` | Missing assertion on computed value |
| Boundary condition | `x > 0` → `x >= 0` | Off-by-one not tested at the boundary |
| Boolean negation | `isValid` → `!isValid` | Condition outcome not asserted |
| Return value deletion | `return result` → `return null` | Caller does not assert the return value |
| Logical connector swap | `&&` → `\|\|` | Combined conditions not tested independently |

---

## Where to Apply

**Apply mutation testing to:**
- Business-critical logic (pricing, tax, discount calculations)
- Validation rules (input sanitization, form validation)
- Authorization and permission checks
- State machine transitions
- Data transformation pipelines

**Skip or deprioritize:**
- UI components and rendering logic (high mutant count, low signal)
- Boilerplate (getters/setters, simple DTOs)
- Generated code
- Infrastructure glue (database connectors, HTTP clients)

---

## CI Integration

- Do **not** run on every commit — mutation testing is slow (minutes to hours depending on suite size).
- Run on a **nightly schedule** or as a **pre-release gate**.
- On PRs: optionally run only on changed files (Stryker and PITest both support incremental mode).
- Publish mutation reports to a dashboard or artifact store; track score trend over time.

---

## Acting on Surviving Mutants

A surviving mutant = a specific test gap. The correct response is a **targeted assertion**, not generic additional tests.

Steps:
1. Read the surviving mutant: what exact change survived?
2. Identify which behavior is not being asserted.
3. Write one assertion that would kill that specific mutant.
4. Re-run to confirm the mutant is now killed.

Do not chase 100% mutation score — some survivors are acceptable (e.g., equivalent mutants that produce identical behavior). Focus effort on critical paths.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.