Skip to content

What is mutation testing?

Mikhail Bodnarchuk

Definition

Mutation testing measures how good your tests are by changing the code on purpose. A tool makes small changes, called mutants, such as turning >= into >, and runs the tests against each one. A failing test kills the mutant; a mutant that survives may point to a check the suite is missing.

How does mutation testing work?

Code coverage tells you which lines your tests ran. It does not tell you whether the tests would notice if those lines were wrong. Mutation testing checks exactly that, by breaking the code on purpose:

  1. Generate mutants. A tool copies your code with one small change per copy: >= becomes >, a condition becomes true, a function body becomes empty. Each changed copy is a mutant, and each kind of change is a mutation operator.
  2. Run the tests against each mutant. Tools can limit each run to the tests that cover the changed line; in the example below, Stryker ran 1.4 tests per mutant on average, out of two.
  3. Classify the result. If at least one test fails, the mutant is killed. If every test passes, it survived.
  4. Score the suite. The share of mutants your tests detect is the mutation score.

PIT, a mutation testing system for Java and the JVM, describes the gap this closes. Line, statement and branch coverage measure "only which code is executed by your tests" and do not check that the tests "are actually able to detect faults in the executed code" (PIT). Stryker (JavaScript and TypeScript, C#, Scala) and PIT are both released under the Apache 2.0 license.

Mutation score vs code coverage: what is the difference?

Code coverageMutation score
Question it answersWhich code did the tests execute?Would the tests fail if this code were wrong?
A test with no assertionsRaises coverageUsually kills nothing
CostOne test runRoughly one test run per mutant, reduced by per-test coverage
Typical useEvery buildChanged code, nightly runs, suite audits

Stryker's metrics page (last changed April 2023, an older source that is still the current doc) defines the score as detected mutants divided by valid mutants, times 100. Detected means killed plus timed out. A timeout counts as detected because, as the page explains, a CI build would catch it: "the tests will never complete."

Mutant stateWhat happenedCounts in the score?
KilledAt least one test failedYes, as detected
SurvivedAll tests passed with the mutant activeYes, as undetected
No coverageNo test runs the mutated codeYes, as undetected
TimeoutThe tests did not finish, for example an infinite loopYes, as detected
Runtime or compile errorThe mutant broke the run or the buildNo
IgnoredExcluded by configuration or another reasonNo, but shown in reports

Example: 100% coverage, one surviving mutant

A shipping rule: orders of 50.00 or more ship free. The function, in src/shipping.js:

// Orders of 50.00 or more ship free; others pay a flat 4.99.
export function shippingFee(total) {
  if (total >= 50) return 0
  return 4.99
}

Its first two tests, in test/shipping.test.js:

import { test, expect } from 'vitest'
import { shippingFee } from '../src/shipping.js'

test('large orders ship free', () => {
  expect(shippingFee(80)).toBe(0)
})

test('small orders pay the flat fee', () => {
  expect(shippingFee(20)).toBe(4.99)
})

Vitest's coverage report for this suite reads 100% on statements, branches, functions and lines. We then ran Stryker with its Vitest runner and this config:

{
  "testRunner": "vitest",
  "mutate": ["src/**/*.js"],
  "reporters": ["clear-text", "progress"],
  "coverageAnalysis": "perTest"
}

Run on 2026-11-19 with @stryker-mutator/core 10.1.1 and Vitest 5.1.1 on Node.js 22.23.5 (excerpt; log lines cut):

$ npx stryker run
15:21:00 (71908) INFO Instrumenter Instrumented 1 source file(s) with 5 mutant(s)

[Survived] EqualityOperator
src/shipping.js:3:7
-     if (total >= 50) return 0
+     if (total > 50) return 0
Tests ran:
    large orders ship free
    small orders pay the flat fee

Ran 1.40 tests per mutant on average.
-------------|------------------|----------|-----------|------------|----------|----------|
             | % Mutation score |          |           |            |          |          |
File         |  total | covered | # killed | # timeout | # survived | # no cov | # errors |
-------------|--------|---------|----------|-----------|------------|----------|----------|
All files    |  80.00 |   80.00 |        4 |         0 |          1 |        0 |        0 |
 shipping.js |  80.00 |   80.00 |        4 |         0 |          1 |        0 |        0 |
-------------|--------|---------|----------|-----------|------------|----------|----------|

Stryker made five mutants: an empty function body (BlockStatement), the condition forced to true and to false (ConditionalExpression), and < and > in place of >= (EqualityOperator). The tests killed four. The survivor is the classic off-by-one: no test checks an order of exactly 50.00, so changing the rule to "more than 50" breaks nothing. We added that test:

test('an order of exactly 50.00 ships free', () => {
  expect(shippingFee(50)).toBe(0)
})

The next run reported 5 killed, 0 survived, and a mutation score of 100.00. Coverage had said 100% both times.

Why is mutation testing slow, and how do teams make it practical?

The cost grows with mutants times tests. Practical Mutation Testing at Scale (Petrović et al., February 2021, an older source), which describes mutation testing at Google, says the traditional approach "does not scale" to a codebase of two billion lines with more than 500,000,000 tests run daily. Its answer has three parts: mutate only code changed in a code review, filter out mutants likely to be irrelevant to developers and limit them per line, and pick operators by how useful they were before. The paper evaluates this with more than 24,000 developers on more than 1,000 projects.

PIT gives similar advice: the most effective use is to run it "frequently against only the code that has been changed." In practice:

  • Pull requests: mutate the changed files only, and report survivors as review comments.
  • Nightly or weekly: a full run to track the score per module.
  • Before a refactor: a full run on the module you are about to change, to find the tests that only look protective.

Can every surviving mutant be killed?

No. Some mutants change the code but not its behavior. These are equivalent mutants. Stryker's equivalent mutants page walks through code where, when two values are equal, swapping >= for <= changes nothing, because both branches then multiply by 10 to the power of 0, which is 1. Stryker says "There is no definitive way for Stryker to find and ignore them." It suggests rewriting such code or accepting that the score stays below 100%. StrykerJS has since added three ways to ignore mutants, including a // Stryker disable comment (Disable mutants), and an ignored mutant does not count against the score. The equivalent mutants page itself dates from October 2020 and ends: "don't be scared of not 100% mutation score!"

So a fixed target such as 100% is the wrong goal. Track the trend per module and read every new survivor in changed code. Treat a survivor as a question: is a test missing, or is the code doing nothing useful?

How does mutation testing help with AI-written tests?

An AI assistant can produce a suite with high coverage and weak assertions. Mutation testing measures exactly that weakness, and it also works the other way round. Meta's ACH system (January 2025, an older source) generates mutants for a specific concern, privacy in the paper, and then has an LLM write tests that kill them. Applied to 10,795 Android Kotlin classes, it generated 9,095 mutants and 571 privacy-hardening tests. In Messenger and WhatsApp test-a-thons, engineers accepted 73% of its tests. Its LLM-based equivalent mutant detector reached a precision of 0.79 and a recall of 0.47, "rising to 0.95 and 0.96 with simple pre-processing".

Mutation testing works best on top of a fast unit layer; the test pyramid entry covers the layers. A survivor in a regression testing suite usually means a missing test, and our test automation guide covers how to decide what to automate. Tests that pass but prove nothing are a problem our QA and test automation team takes on: we audit suites, drop tests that check nothing important, and review AI-drafted tests for real assertions and edge cases.

Sources

  1. Real world mutation testing, PIT (pitest.org), 2026-04-20
  2. Mutant states and metrics, Stryker Mutator docs, 2023-04-14
  3. Equivalent mutants, Stryker Mutator docs, 2020-10-23
  4. Practical Mutation Testing at Scale, arXiv (Petrović, Ivanković, Fraser, Just), 2021-02-26
  5. Mutation-Guided LLM-based Test Generation at Meta, arXiv (Foster, Gulati, Harman and others; Meta), 2025-01-22
  6. pitest, PIT (GitHub, hcoles/pitest), 2026-11-16
  7. Disable mutants, Stryker Mutator docs (StrykerJS), 2026-07-13

Frequently asked questions

Is mutation testing white-box or black-box testing?

White-box. The tool needs the source or bytecode to create mutants, and it judges the tests against that code. It says nothing directly about whether the product meets its requirements.

What is a good mutation score?

There is no universal number. Equivalent mutants can keep some code below 100%, and a high score on trivial code means little. Compare modules over time and look at survivors in code that changed.

Does mutation testing replace code coverage?

No. Coverage is cheap and shows code no test runs at all; mutation testing is expensive and shows code that runs without being checked. A practical split is coverage on every build and mutation testing on changed code.

Which mutation testing tools are there for each language?

Stryker covers JavaScript and TypeScript (StrykerJS), C# (Stryker.NET) and Scala (Stryker4s). PIT is for Java and works with Ant, Maven, Gradle and other build tools.

Building with AI agents? Talk to an engineer.