← blog
· series: Measured

Mutation Testing in CI Without the Bill: 4.5 to 6.8 Seconds, Not 70.5 to 107.4

On GitHub-hosted runners, an incremental Stryker run on a pull request takes 4.5 to 6.8 seconds. A full run takes 70.5 to 107.4. Same machine, same result for every mutant.

On a pull request, an incremental Stryker run takes 4.5 to 6.8 seconds. A full run on the same runners takes 70.5 to 107.4. On each runner, incremental is 15.67 to 16.17 times faster than full, and a run limited to the changed file is 8.1 to 8.26 times faster. Chapter 4 got the score to 88.72%. This chapter makes the check cheap enough to run on every pull request, and makes it fail the build when the score drops.

Chapter 5 of Mutation Testing for the AI Era. The workflows, the config, the timing script and the raw results are in the PoC repo.

The cost problem

A mutation run tests every mutant against the suite. ufo has 1011 mutants, and a full run on a GitHub-hosted runner took 70.5 to 107.4 seconds. ufo is small. The cost grows with the number of mutants and the tests that run for each one, so a larger repo pays far more, on every push.

Most of that work is repeated. A pull request changes a few lines, and almost every mutant sits in code the pull request did not touch. The three modes below skip that work in different ways.

Survivors in an OSS subject are suite gaps, not bugs. The subject is unjs/ufo at f06c800, with its own suite. This chapter uses it as a timing subject.

The baseline here is 82.59%, the chapter 3 score, not chapter 4's 88.72%. The chapter 5 config runs ufo's own suite without the chapter 4 tests, with Stryker's default bail. I chose that so the timings are those of a plain run. The chapter 4 config adds kills/ and sets disableBail, and each of its runs took the CI runner 395 to 407 seconds.

Three modes

All three use one config, stryker.ch5.config.mjs:

import base from './stryker.config.mjs';
 
export default {
  ...base,
  reporters: ['clear-text', 'json'],
  clearTextReporter: { reportTests: false },
  jsonReporter: { fileName: 'reports/ch5/mutation.json' },
  incrementalFile: 'reports/ch5/stryker-incremental.json',
  thresholds: { high: 90, low: 85, break: 80 },
};

The config does not turn incremental mode on. Each mode passes its own flags:

  • Full: npx stryker run stryker.ch5.config.mjs --incremental --force. Runs every mutant and rewrites the baseline file.
  • Incremental: npx stryker run stryker.ch5.config.mjs --incremental. Reads the baseline and reuses the result of every mutant whose code and covering tests did not change.
  • Changed files: npx stryker run stryker.ch5.config.mjs --mutate subject/src/query.ts. Mutates only the files you list and reuses nothing.

How I measured it

The change is one line in subject/src/query.ts: s.length < 2 becomes s.length <= 1. The behaviour is the same, so the suite stays green. It changes 7 mutants.

A script, scripts/measure-ch5.mjs, runs four modes in order on one runner:

  1. full on the clean tree. This builds the baseline.
  2. incremental on the changed tree, with the baseline.
  3. changed-files on the changed tree, mutating query.ts only.
  4. full-changed, a full run on the changed tree.

The Measure ch5 workflow runs the script as 3 jobs, one per runner. Every run uses StrykerJS 10.1.1, Vitest 4.1.5 and Node v24.14.1 on ufo f06c800. That is 3 runs per mode.

Results

ModeWall timeMutants testedMutants reusedScore
full70.5-107.4 s1011082.59%
incremental4.5-6.8 s7100482.59%
changed files8.7-13 s78085.9%

Incremental tests 7 mutants and reuses 1004. Its score, 82.59%, is the score of the full run, because the reused results are real results from the baseline.

The changed files score, 85.9%, is for query.ts only. It has 78 mutants, and the run tests all of them. It is not a project score.

Compare within a run, not across runs

The 3 runners had 3 different CPU models, so the full run spans 70.5 to 107.4 seconds:

RunCPUfullincrementalchanged filesFull / incrementalFull / changed files
1AMD EPYC 9V4570.5 s4.5 s8.7 s15.678.1
2AMD EPYC 9V7484.1 s5.2 s10.3 s16.178.17
3AMD EPYC 7763107.4 s6.8 s13 s15.798.26

Each runner had 4 CPUs. A ratio of the medians across runs would mix hardware with mode. The ratio inside one run does not, and it stays in a narrow band: 15.67 to 16.17 for incremental and 8.1 to 8.26 for changed files. Quote the speedup, not the seconds. Seconds depend on the runner you get.

Does incremental give the same answer?

Fast is no use if it is wrong. The fourth mode, full-changed, runs every mutant on the changed tree. I compared it with the incremental run, mutant by mutant, on whether each one is detected (Killed or Timeout) or not. They differ on 0 mutants in all 3 runs. Both runs also score 82.59%.

The gate

thresholds.break is the gate. When the score falls below it, Stryker exits with code 1, and the job fails. The baseline is 82.59%, and I set break to 80. That leaves 2.59 points of room.

I checked that the gate fails. With break at 90, a local run printed Final mutation score 82.99 under breaking threshold 90, setting exit code to 1 (failure). and exited 1. The local score is 82.99%, not 82.59%: 25 mutants timed out on my machine and 12 on the runner, and Stryker counts a timeout as detected. The config, the full output and the exit code are in the repo. The committed config keeps break at 80.

Pick break just under your current score, then raise it as the score rises. A value far under the score never fails.

The workflow

On a pull request, the job restores the baseline, runs incremental, then runs the changed files:

- uses: actions/cache/restore@v6
  with:
    path: reports/ch5/stryker-incremental.json
    key: stryker-incremental-none
    restore-keys: stryker-incremental-
- name: Stryker, incremental, gated by thresholds.break
  run: npx stryker run stryker.ch5.config.mjs --incremental
- name: Stryker, changed files only
  run: |
    files=$(git diff --name-only --diff-filter=d origin/${{ github.base_ref }}...HEAD -- 'subject/src/*.ts' | grep -v '^subject/src/index.ts$' | paste -sd, -)
    if [ -z "$files" ]; then echo "no mutated file changed"; exit 0; fi
    npx stryker run stryker.ch5.config.mjs --mutate "$files"

The nightly run, at 03:17 UTC, and any manual dispatch run full and save the baseline:

- name: Stryker, full run, rebuilds the baseline
  run: npx stryker run stryker.ch5.config.mjs --incremental --force
- uses: actions/cache/save@v6
  if: always() && github.ref == 'refs/heads/main'
  with:
    path: reports/ch5/stryker-incremental.json
    key: stryker-incremental-${{ github.run_id }}

I ran this on a real pull request, a demo change that I closed afterwards. First, a manual full run on main logged Cache saved with key: stryker-incremental-46964796850. The pull request run then logged Cache restored from key: stryker-incremental-46964796850, and Stryker reused 1004 of 1011 mutant results. The score was 82.59%, over break. The changed files step mutated query.ts only: 78 mutants, 85.9%, also over break. Both logs are in results/ch5-workflow (baseline.log and pr-warm.log), and runs.json there lists the run IDs. The pull request run is here.

Cache, not artifact

The baseline file lives in the Actions cache, not in an artifact. The reasons:

  • A pull request can restore a cache that main saved. restore-keys picks the newest stryker-incremental-* entry. To fetch an artifact, the job would have to look up the last good run through the API first.
  • Pull requests only restore. Only a full run on main saves: the nightly run, or a manual dispatch. A pull request cannot overwrite the baseline, so main stays the only source.
  • The baseline can be up to a day old. Incremental mode compares the mutated files and the test files with the current ones, so a pull request still gets fresh results for what it changed. The Stryker docs say what it cannot see: "Stryker will not detect any changes you've made in files other than mutated files and test files." Updated dev dependencies and environment changes are in that list. That is why the nightly run uses --force: it re-tests every mutant and rebuilds the baseline.

The first pull request is cold

With no cache, there is no baseline. The first pull request in my run logged Cache not found and tested all 1011 mutants. Its log is pr-cold.log. That is a full run, so it costs a full run. After the nightly run saves a baseline, pull requests take the incremental path.

What didn't work

  • The first draft of the measure script, at eb2d02a, computed the speedup as a ratio of medians across runs. With 3 CPU models, that number mixed hardware and mode. On these medians it gives 84.1 / 5.2, stored as 16.173099999999998. I replaced it with the per-run ratio, rounded to 2 decimals.
  • The cache steps could only be checked by real runs. The cold run and the warm run above are those runs.

Limits

One library, one commit, one small change, 3 runners. Incremental cost grows with the reach of the change: a change to a helper that many tests cover re-tests more mutants than 7. The Stryker docs also say a killed mutant is reused only while its killing test still exists and did not change, and a survivor is reused only if no new test covers it and no tests changed. So a test change re-runs the mutants it touches.

With --mutate, the break threshold applies to the changed files' own score, not the project's. A file with few mutants can pass or fail on one mutant. The incremental step gates the whole project, so run both.

Use incremental on pull requests, full on a schedule, and break just under your score. Compare modes on one runner, and trust ratios more than seconds.

Everything above is reproducible: qa-gary-parker/poc-mutation-testing-ufo. The timing run is on GitHub, and its output is in results/ch5-ci. Measured with StrykerJS 10.1.1 and Vitest 4.1.5 on ufo f06c800, 3 runs per mode, one per runner.

related

QA Ark Newsletter

Test automation, AI in testing and quality engineering practice. No spam, unsubscribe any time.