We use analytics to count visits and form use. It is on unless you reject it. We show no ads on this site.

Glossary

Mutation testing

Published . Last updated . Published by Zapple.Tech, founded by the founders of CodeceptJS and Codeception, open-source testing frameworks.

Published
Updated
Definition

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 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 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.

Mutation testing: a tool changes one operator in the code, age >= 18 becomes age > 18, and the tests run against the mutant; a failing test kills it, and a mutant that survives marks behavior no test checks

How is the mutation score calculated?

The Stryker page on 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 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 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 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.

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 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. 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, 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.

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 page.

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

  • Test-driven development

    Test-driven development (TDD) is a programming workflow in which a developer turns one planned scenario into a failing automated test, writes just enough code to make it pass, optionally refactors, and repeats until the test list is empty. The tests direct the design of the code, so TDD is a way of writing code, not a test phase run afterwards.

  • Test pyramid

    The test pyramid is a model for spreading automated tests across levels: many fast unit tests at the base, fewer service tests in the middle, and few slow end-to-end tests through the user interface at the top. Mike Cohn described it as the test automation pyramid. It guides proportions, not exact ratios: tests higher up are slower and cost more.

All terms in the glossary

Service

Custom test framework development

Test automation framework development: a framework set up or reworked for your stack, repository and CI, from the founders of CodeceptJS and Codeception.

See the service

Questions about mutation testing

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.

Request a QA audit quote

Tell us what you ship and what worries you.

What happens after you send this

  1. You send the form: your situation and what you need tested, then your name and work email.
  2. Within one business day, we reply with a suggested first step, its scope, timeline and a quote.
  • Fixed scope
  • You decide after each step
  • The tests live in your repository
  • An NDA signed before access

“They helped us to close the positions and consult our team how to proceed further. High-quality quick feedbacks with the deep checking of the required tasks, professional approach, great understanding of the company's technologies and product, detailed reports.”

Kristina Lavrentieva, Manager at keepgo.com, Israel
  • Rated 4.9 out of 5 on Clutch, from 7 client reviews
  • 42 completed test automation and infrastructure projects
  • Founded by the founders of CodeceptJS and Codeception, open-source testing frameworks

Request a QA audit quote

    What is closest to your situation?
    Optional. The product, the platforms, how often you release, what broke last.

    You decide after our reply whether to go ahead.

    Prefer to talk first? Book a call

    One-week QA audit · written report

    Request a QA audit quote