Managed IT · October 6, 2026 · intSignal Team

Mutation Testing Found the Safeguards Our Tests Weren't Actually Checking

Share this article

A passing test suite answers a narrower question than people think. It says: with this code, these assertions hold. It does not say: if this code were wrong, these assertions would fail.

Those come apart more often than is comfortable. The way to tell them apart is to break the code deliberately and check that the suite notices.

The method

For each safeguard in a module, write a mutant: a specific weakening, described in the language of what it would mean in production. Apply it to a copy, run the suite against that copy, and record whether the suite failed. A mutant that survives is a safeguard with no test behind it.

const mutants = [
  ["unknown next value is guessed as checkout", `default: return null;`, `default: return "checkout";`],
  ["any checkout url is followed", `url.startsWith("https://checkout.stripe.com/")`, `url.length > 0`],
  ["seats lose their floor", `Math.min(10_000, Math.max(1, n))`, `Math.min(10_000, n)`],
  ["rate limits no longer flagged", `code === "too_many_attempts" || code === "too_many_sends"`, `false`],
];

for (const [name, from, to] of mutants) {
  writeFileSync(MUT, src.replace(from, to));
  const r = spawnSync(process.execPath, ["test.mjs"], { env: { ...process.env, MOD: MUT } });
  if (r.status === 0) console.log(`SURVIVED: ${name}`);
}

The module under test is imported through an environment variable so the same suite can run against the real file or a mutated copy. That is the only production change required.

No framework needed. A hundred lines of Node and an honest list of what each safeguard is for.

What it actually found

An off-by-one that every test agreed with

We classify a non-JSON API response by status: >= 500 means the server is at fault and the user should be told so. The mutant changed it to > 500.

Every test passed.

Our cases used 502 and 404 — neither of which distinguishes the two. A plain 500 Internal Server Error would have been classified as a client mistake, and a person hitting a crashed endpoint would have been told to check their details. The fix was a test, not code:

for (const s of [500, 502, 503, 504]) {
  const out = await postJson("/x", {}, async () => ({ status: s, json: async () => { throw new Error(); } }));
  check(`a ${s} is a server fault`, out.error === "server_error");
}

Boundaries are where mutation testing earns its keep, because they are exactly where a plausible test case can sit entirely on one side without anyone noticing.

A feature flag with nothing stopping it

One mutant flipped a rollout flag from false to true — the flag controlling whether we send a new set of product identifiers to a billing system that had not deployed them yet.

It survived. The suite was perfectly happy to point every checkout at a catalogue that did not exist.

The fix is one line that looks pointless and is not:

check("the catalogue cutover has not been flipped yet", CATALOG_CUTOVER_DONE === false);

Now the flag cannot move as a side effect of an unrelated change.

Messages that quietly become accusations

We mutate copy too, because wording is a safeguard when it governs what someone does next:

["a server fault reads as the user's mistake",
  `server_error: "Something on our end is down right now — this isn't you…"`,
  `server_error: "Please check your details and try again."`],

The test that kills it asserts the message does not blame the person:

check("a server fault is not blamed on the person",
  !/check your details|start again/i.test(messageFor("server_error")));

That is a real requirement. Treating it as one keeps it from being edited away by someone tidying up copy.

Writing mutants that are worth running

The failure mode is mutants that are technically valid and operationally meaningless — flipping a comparison in code where either answer is fine. You get a number that goes up without learning anything.

Two rules keep them useful:

Name the consequence, not the edit. "Credentials sent on anonymous endpoints" is a mutant worth running. "Changed omit to include" is the same edit with the meaning stripped out. If you cannot name the consequence in plain language, the mutant is probably not interesting.

Mutate safeguards, not implementation details. The question is "does the suite defend this property", not "is the code covered". Target the clamps, the allow-lists, the boundaries, the error classifications, the flags.

Equivalent mutants are normal

Some survivors are not failures of your tests — they are changes with no observable effect. We have one: a defensive guard that returns early when a lookup table is empty, duplicated by a later check that returns the same thing. Removing it changes nothing anyone can observe.

Do not contort tests to kill those. Note them and move on. A survivor list of two with written explanations is more valuable than a 100% score achieved by writing tests that assert implementation rather than behaviour.

Where it pays

We run this over the modules where being wrong is expensive: anything handling money, anything deciding what is sent to an external system, anything classifying errors, anything gating a rollout. Across those, the suites now sit at 44 of 44, 38 of 38, and 23 of 23 mutants killed — and the ones that got us there were almost all tests we would never have thought to write, because the code looked obviously correct and the suite was already green.

That is the point. Coverage tells you which lines ran. Mutation testing tells you which lines are defended — and the gap between those two is where production bugs live.

Share this article