# Mutation testing: find the gaps in passing tests

> Run a Stryker mutation testing example. Inspect a surviving delivery-boundary mutant, add the missing assertion and compare native reports.

Source: https://cueapril.com/testing/mutation-testing
Updated: 2026-10-15
Index: https://cueapril.com/llms.txt

## What is mutation testing?

Mutation testing checks whether your tests notice small, deliberate edits to code, called mutants. It runs the tests against each edit. A mutant that survives may expose a missing assertion, an unclear requirement or a change that makes no relevant behavioural difference.

A passing suite tells you what its assertions checked. Mutation testing asks a useful follow-up: would those tests notice a change in behaviour? With Cue April, run approved Stryker mutation checks alongside your other tests and see which deliberate code changes survive.

## A passing suite can miss an important boundary.

The fictional requirement is free delivery from 5000p. The correct function uses >=, but these two tests check only 4999p and 5001p. Both pass when that operator is changed to >. Stryker makes that controlled source change so we can see whether the suite notices it.

src/delivery.mjs: the correct code under mutation test

```javascript
// Fictional requirement: delivery costs 500p below £50 and is free from £50.
// The example accepts a non-negative integer basket value in pence.
export function deliveryPence(basketPence) {
  return basketPence >= 5000 ? 0 : 500;
}
```

test/weak.test.mjs: the two-example suite

```javascript
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { deliveryPence } from '../src/delivery.mjs';

test('charges below the threshold', () => assert.equal(deliveryPence(4999), 500));
test('is free above the threshold', () => assert.equal(deliveryPence(5001), 0));
```

## Run Stryker on one source file.

The download pins Stryker 10.0.0 and uses its command runner with Node’s built-in test runner. This keeps the example small: one source file, two tests and a single mutation worker. Coverage analysis is disabled because the command runner executes the suite as a command. [Stryker’s configuration reference](https://stryker-mutator.io/docs/stryker-js/configuration/) explains these options.

stryker.weak.json

```json
{
  "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
  "mutate": ["src/delivery.mjs"],
  "testRunner": "command",
  "commandRunner": { "command": "node --test test/weak.test.mjs" },
  "coverageAnalysis": "off",
  "concurrency": 1,
  "reporters": ["clear-text", "json"],
  "jsonReporter": { "fileName": "results/mutation-weak.json" },
  "tempDirName": ".stryker-tmp-weak"
}
```

Run from the downloaded example folder with Node 24

```bash
npm ci --ignore-scripts
npm run test:weak
npm run test:mutation:weak
```

## Investigate the survivor before changing a test.

The native weak-suite report contains five mutants: four were killed and one survived. The survivor changes basketPence >= 5000 to basketPence > 5000. The independent requirement says exactly 5000p gets free delivery, so this survivor identifies a missing boundary assertion. Other survivors can be equivalent changes or uncover unclear requirements; their status alone does not decide what to change.

Observed local results from the two native JSON reports

```text
Two-test suite:   5 mutants, 4 killed, 1 survived
Boundary mutant:  basketPence > 5000
Status:           Survived

Three-test suite: 5 mutants, 5 killed, 0 survived
Boundary mutant:  basketPence > 5000
Status:           Killed
```

## Add the boundary assertion and run again.

The stronger suite adds the exact threshold. Its fresh Stryker run killed all five mutants, including the former survivor. That is a result for this tiny fixture, not a universal mutation-score target or a claim about customer code. Both native reports and source variants are in the download.

test/strong.test.mjs: preserve the requirement explicitly

```javascript
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { deliveryPence } from '../src/delivery.mjs';

test('charges below the threshold', () => assert.equal(deliveryPence(4999), 500));
test('is free at the threshold', () => assert.equal(deliveryPence(5000), 0));
test('is free above the threshold', () => assert.equal(deliveryPence(5001), 0));
```

Run the stronger suite and compare reports

```bash
npm test
npm run test:mutation:strong
# Inspect results/mutation-weak.json and results/mutation-strong.json
```

## Choose the next assertion from the requirement.

Mutation testing works best on a bounded rule whose expected behaviour is clear. Review each survivor against that rule, then decide whether to add an assertion, clarify the requirement or document an equivalent mutation. Keep errors, timeouts and untested scope visible. The [recorded sample report](/sample-report) is a separate owned fixture with twelve mutations and six survivors; its totals should not be combined with this guide’s five-mutant example.

## Use mutation evidence in a release review.

Cue April supports approved Stryker checks alongside other testing methods and retains the native outcomes for review. Agree the source scope, runner setup and compute allowance first. [Property-based checks](/testing/property-based-testing) investigate input combinations, while mutations challenge the assertions that should catch changed behaviour. Your team reviews the findings and decides what ships. [Review ways to start](/pricing).

## Reproduce the example

A fictional delivery rule with a deliberately seeded boundary defect. These examples were executed locally. They contain no customer data, AI calls or hosted Cue April execution.

Verified 2026-10-15 with Node 24.21.0, fast-check 4.10.2, Stryker 10.0.0 and Cucumber 13.3.0.

[Download runnable examples](https://cueapril.com/examples/testing-business-rules.zip)

[Read source and recorded results](https://cueapril.com/examples/testing-business-rules/index.html)

## Primary documentation

- [StrykerJS: getting started](https://stryker-mutator.io/docs/stryker-js/getting-started/)
- [StrykerJS: command runner and mutation configuration](https://stryker-mutator.io/docs/stryker-js/configuration/)

By Cue April. Updated 2026-10-15.

## Questions

### Does every surviving mutant mean there is a bug?

A survivor needs investigation. It may expose a missing assertion, an unclear requirement or a change that makes no relevant behavioural difference. The report keeps that uncertainty visible.

### Can I inspect a real sample?

The public owned sample retains twelve generated mutants, including six survivors. You can inspect its measured outcomes and evidence pack before discussing an evaluation.

### What is a good mutation score?

There is no universal target. A mutation score describes only the code and mutants that ran, so compare it over time on the same scope instead of across projects. Treat each surviving mutant as a prompt to check an assertion or a requirement.

### Is mutation testing worth it?

It pays off most on code where a missed bug is expensive, such as pricing rules or access decisions. Mutation runs take longer than a normal test run, so start with a focused slice of the repository instead of the whole codebase.

### What are the disadvantages of mutation testing?

It costs more compute than a normal run, because the tests run against every mutant. Some mutants make no behavioural difference and survive for a good reason, so each survivor needs review before anyone changes the tests.

## Related

- [Property-based testing](https://cueapril.com/testing/property-based-testing): Run a fast-check property-based testing example: find a delivery-rule boundary fault, replay its seed and counterexample, and verify the fix.
- [Unit testing](https://cueapril.com/testing/unit-testing): Unit testing explained, with examples. Run your Jest or Vitest suites against a pinned code revision and inspect the native results and remaining gaps.
- [Testing AI-generated code](https://cueapril.com/guides/testing-ai-generated-code): Review AI-generated code with an independent requirement, a runnable boundary example, actual fast-check and Stryker results, and a before-merge checklist.
