# Mutation testing

> Mutation Testing: What It Is and What the Score Tells You. Canonical page: <https://zapple.tech/glossary/mutation-testing/>

Mutation testing measures how good a test suite is by making small deliberate changes, called mutants, to the code and running the tests against each one. A failing test kills the mutant; a surviving mutant marks behavior the tests do not check. Unlike code coverage, the mutation score shows whether tests would notice a change, not only which lines ran.

## What gap in code coverage does mutation testing close?

Code coverage tells you which lines your tests ran. It does not tell you whether the tests would notice if those lines were wrong. The [PIT documentation](https://pitest.org/) says the same: traditional coverage measures only which code is executed by your tests, and does not check that the tests can detect faults in the code they executed.

Mutation testing closes that gap. The [Stryker documentation](https://stryker-mutator.io/docs/) describes the loop: bugs, called mutants, are inserted into your production code, and your tests run once for each mutant. If a test fails, the mutant is killed. If all tests pass, the mutant survived, and Stryker's own example reads a surviving mutant as a probable missing test.

A simple case: a function allows entry at `age >= 18`. A tool changes it to `age > 18`. If no test uses an 18-year-old, nothing fails, and the suite has a hole that a coverage report never showed.

## How is the mutation score calculated?

The Stryker page on [mutant states and metrics](https://stryker-mutator.io/docs/mutation-testing-elements/mutant-states-and-metrics/) defines it as detected mutants divided by valid mutants, times 100. Three details matter when you read a report:

- A mutant that makes the tests time out counts as detected, because a real build would notice a test that never ends.
- Mutants that fail to compile or crash the test runner are not part of the score.
- Ignored mutants do not count against it but still show in the report.

The [Infection documentation](https://infection.github.io/guide/) for PHP calls its score the Mutation Score Indicator and describes mutation testing as a fault-based technique. The formula differs: Infection counts mutants that end in an error as defeated and divides by all mutants, while Stryker leaves error mutants out of the score. Tools also differ in the mutations they model, so compare scores only within one tool and one configuration.

## How does mutation testing compare with code coverage?

| | Code coverage | Mutation testing |
|:--|:--|:--|
| Question it answers | Did the tests run this line? | Would the tests fail if this line were wrong? |
| A test with no assertions | Counts as covered | Kills a mutant only if the change makes the code crash or hang |
| Cost to run | Low, a by-product of the test run | Higher: the tests run once per mutant |
| Typical use | A quick map of untested code | A check on the quality of tests on code that matters |
| What a high number proves | Little on its own | That the tests caught the changes the tool tried |

## When is mutation testing worth running, and when is it not?

Our rule of thumb: run it where a wrong result is expensive and the logic is dense, such as pricing, refunds, permissions, date windows and validation. It is also useful when you inherit a suite with high coverage and little trust, or when code is written quickly, for example with AI assistants, and you want to know whether the tests would catch a change. Our [AI code review checklist](/blog/types-of-automation-testing/ai-code-review-checklist/) includes a mutation check on generated code.

We would not run it everywhere. In glue code, thin controllers and UI layout, expect many mutants and little insight. The cost is real: the [StrykerJS documentation](https://stryker-mutator.io/docs/stryker-js/incremental/) says mutation testing still takes time, and offers incremental mode so only changed code is re-tested. A practical setup is to run it on the modules that matter, on changed files in the pull request, and on a schedule for the rest. For a suite whose tests need rebuilding, see [custom framework development](/services/custom-framework-development/).

## What mistakes do teams make with mutation testing?

- **Chasing 100%.** Some surviving mutants are equivalent: the change does not alter behavior, so no test can kill it. The Stryker page on [equivalent mutants](https://stryker-mutator.io/docs/mutation-testing-elements/equivalent-mutants/) says there is no definitive way for the tool to find and ignore them. Reading each survivor beats raising the number.
- **Setting a hard threshold on day one.** StrykerJS defaults to 80 as high and 60 as low, with no failing threshold unless you set one in its [configuration](https://stryker-mutator.io/docs/stryker-js/configuration/). Start by reading reports, then gate on a number you have seen move.
- **Treating the score as complete.** A score covers only the mutants a tool models. A score of 100% means those mutants were caught, not that the code has no bugs.
- **Running it on everything, every commit.** The build slows and people stop looking at the results.

In the [introduction to mutation testing](/blog/types-of-automation-testing/introduction-to-mutation-testing/), Bas Dijkstra argues that code coverage alone is not a good enough indicator of test quality. For the unit-level tools that sit underneath it, see the [comparison of unit testing tools](/blog/types-of-automation-testing/list-of-the-best-unit-automation-testing-tools/).

## What does Zapple.Tech do about it?

A surviving mutant points to a test that runs the code but checks too little. Zapple.Tech starts with a one-week QA audit of one product area. It looks at its tests, pipeline and release process, and ends in a written report on what is at risk and what to fix first, plus a pilot plan you can run with Zapple.Tech or without it. Read more on the [QA audit and assessment](/services/audit-and-assessment/) page.

If the audit shows tests that need rebuilding, [custom framework development](/services/custom-framework-development/) covers it. Tell us about your suite in the form below. More terms are in the [QA glossary](/glossary/).

## FAQ

### What is mutation testing?

Mutation testing checks how good a test suite is. A tool makes small deliberate changes to the code, called mutants, and runs the tests against each one. If a test fails, the mutant is killed; if all pass, it survived. The mutation score is the share of mutants the tests detect. A surviving mutant points to behavior no test checks, even when line coverage is 100%.

### What is a good mutation score?

There is no universal number. StrykerJS ships default thresholds of 80 for high and 60 for low, and no failing threshold unless you set one. Treat them as starting points. A payment calculation deserves a higher bar than a settings screen, and a score is only meaningful alongside a look at the surviving mutants.

### What is the difference between mutation testing and code coverage?

Code coverage measures which code your tests executed. Mutation testing measures whether your tests would fail if the code were wrong. A test with no assertions can give full coverage and still kill no mutants, which is why the two numbers can disagree.

### Does mutation testing slow down the build?

It can. A tool runs your tests once per mutant, so large codebases take longer. The StrykerJS documentation says mutation testing still takes time even with its speed-ups, and offers an incremental mode that tests only changed code. You can run it on changed files or on a schedule instead of on every commit.

## Sources

- [Stryker Mutator documentation, What is mutation testing?](https://stryker-mutator.io/docs/)
- [Stryker Mutator documentation, Mutant states and metrics](https://stryker-mutator.io/docs/mutation-testing-elements/mutant-states-and-metrics/)
- [Stryker Mutator documentation, StrykerJS configuration (thresholds)](https://stryker-mutator.io/docs/stryker-js/configuration/)
- [Stryker Mutator documentation, StrykerJS incremental mode](https://stryker-mutator.io/docs/stryker-js/incremental/)
- [Stryker Mutator documentation, Equivalent mutants](https://stryker-mutator.io/docs/mutation-testing-elements/equivalent-mutants/)
- [PIT mutation testing, What is mutation testing?](https://pitest.org/)
- [Infection documentation, Introduction](https://infection.github.io/guide/)
