---
name: arfin-parween-tests-that-bite
title: tests that bite
kind: skill
description: >
  Prove that tests actually catch bugs. Plants small, realistic bugs (mutants)
  in the code under test, runs the suite, and rewrites or adds tests until every
  real bug is caught. Use whenever you write, add, or review tests, or the user
  asks whether tests are any good, says "tests pass but the bug shipped", "these
  tests are useless", "AI wrote these tests", "check test quality", "mutation
  testing", "harden the tests", or wants test coverage that means something.
  Also use after writing tests for a feature or bug fix, before calling the work
  done, even if the user did not ask for mutation testing b
updated: 2026-12-05
authored_by: arfin-parween
author_url: https://github.com/arfin-parween
source_url: https://github.com/arfin-parween/tests-that-bite
brought_by: kt
license: MIT
---

# Tests That Bite

A test is only worth what it catches. A suite that stays green when the code is wrong is worse than no suite, because it gives false confidence. Coverage numbers don't measure this: a line can be "covered" by a test that asserts nothing about it.

This skill measures it directly. Break the code on purpose in small, realistic ways, run the tests, and see which breakages slip through. Every survivor is a bug a real user could ship. Close each gap with a test that fails for that bug, then show the before/after score.

## The workflow

### 1. Get a green, fast baseline

Find the code under test and the narrowest test command that exercises it (one file or module, not the whole monorepo). Run it. If it isn't green on unmodified code, stop and tell the user. Mutation results mean nothing on a red suite.

Prefer a command that stops at the first failure (`pytest -x`, `jest --bail`, `go test -failfast`), because each mutant only needs one failing test to count as caught.

### 2. Read the tests for the usual weaknesses

Before mutating anything, skim the tests for these patterns. They predict where mutants will survive, and noting them helps you aim the mutants:

- **Asserting existence, not value**: `is not None`, `> 0`, `isinstance`, `toBeDefined()`, `len(x) > 0`.
- **Asserting on mocks, not outcomes**: "the function was called once" while the real result goes unchecked.
- **Mocking the thing under test**, or mocking so much that only the wiring is tested.
- **Recomputing the expected value with the code under test** (`assert f(x) == f(x)` in disguise). Expected values should be computed independently, by hand or from the spec.
- **Missing boundaries**: only "typical" inputs, never the exact threshold, empty input, zero, the last element, or the error path.
- **Overly broad exception checks**: `pytest.raises(Exception)` passes for the wrong error too.

### 3. Design mutants: small, realistic, and aimed

This step decides whether the skill is useful. Crude mutants (return `None`, delete the function body, raise everywhere) are caught by almost any suite. They inflate the score and teach nothing. Plant bugs that a tired developer or a model could plausibly write and that a code reviewer might miss.

Get them from, in this order of preference:

1. **Real history.** If the repo uses git, look for past fixes in the code under test: `git log --oneline -i -E --grep="fix|bug|regress" -- <path>`, then `git show <sha> -- <path>`. Re-introducing an old bug as a mutant is the most convincing test there is: it already happened once.
2. **The spec and docstrings.** Every rule in a comment, docstring, ticket, or README is a mutant waiting to happen ("free shipping at 50 or more", "case-insensitive", "retries 3 times").
3. **The catalog.** `references/mutant-catalog.md` lists subtle mutation patterns by category, with examples for several languages. Read it the first time you use this skill in a session.

Aim for 6-12 mutants for a typical module, spread across different behaviours. Don't pile them all on one line. Each one should change observable behaviour; if you're not sure it does, think it through before including it (see step 5 on equivalents).

### 4. Run them with the bundled script

Write the mutants to a JSON file outside the source tree (for example in the system temp directory) and run:

```bash
python <skill-dir>/scripts/mutate.py --mutants mutants.json --cwd <project-root> \
  --cmd "<narrow test command>" --json results.json
```

Each mutant is `{"id", "file", "find", "replace", "why"}`. `find` must occur exactly once in the file, so include enough surrounding text to make it unique. The script runs the baseline, applies one mutant at a time, runs the tests, and restores the file every time, even on Ctrl-C. If a run is ever killed hard, `--restore` puts files back.

Use the script rather than editing files by hand, because a hand-applied mutant that is not reverted is a real bug in the user's code. After the run, confirm with `git status` / `git diff` that only the intended files changed.

The script needs only Python 3. It works for any language as long as the test command's exit code is non-zero when tests fail. For compiled languages the build happens inside the test command; that's fine, just slower.

### 5. Triage every survivor

For each surviving mutant, decide which it is:

- **A gap**: the mutant changes behaviour a user could notice and no test checks it. Write or strengthen a test that fails with the mutant and passes without it.
- **Equivalent**: the mutant cannot change behaviour (e.g. clamping a value that can never go out of range). Say why in one sentence, mark it `"equivalent": true`, and move on. Don't write a test that pokes at internals just to kill it.
- **Unreachable or dead code**: worth mentioning to the user as a cleanup, not as a test gap.

When writing the new tests:

- Assert on **concrete values** computed independently (by hand, from the spec, or from a worked example in a comment). `assert total == 50.99`, not `assert total > 0`.
- Assert on **outputs and state**, not on which internal functions were called. Mock only at real boundaries: network, clock, randomness, filesystem, third-party APIs.
- Test **the exact boundary**, both sides of it.
- Name each test after the **behaviour** it protects (`test_free_shipping_uses_discounted_subtotal`), so the next person knows what breaks if it fails.
- Follow the project's existing test style, framework, and file layout. Don't introduce a new library to do this.
- Keep the tests that already work; rewrite the ones that check nothing. Deleting a toothless test is fine when a stronger one replaces it.

### 6. Rerun and report

Rerun the script with the same mutants until every non-equivalent mutant is killed, or until a remaining survivor needs a decision from the user (e.g. the "bug" might actually be the intended behaviour). Then report:

```
## Tests that bite: <module>

Mutation score: <before> -> <after>   (equivalent mutants excluded)

| Mutant | Bug planted | Before | After | Test that now catches it |
|---|---|---|---|---|
| M1 | free shipping at exactly 50.00 lost | survived | killed | test_shipping_cost[50.00-US-0.0] |
...

Equivalent (not scored): M9 – clamp can never trigger because no rate is >= 100%.
Questions for you: <any survivor whose correct behaviour is unclear>
```

Keep the report short. The table is the proof; the user can read the tests for the details.

## Scaling the effort

- **Quick check** (the user wrote one small test, or you're finishing a small fix): 3-4 targeted mutants on the lines you changed. Still use the script; it's fast.
- **Normal** (a feature or module): the full workflow above.
- **Large suites**: work one module at a time, highest-risk first (money, auth, data loss, anything with a past bug). Tell the user which modules you covered and which you didn't.

If the project already has a mutation tool configured (mutmut, Stryker, PIT, cargo-mutants, go-mutesting), you can use it as well. Its mutants are mostly mechanical, though, so still add the hand-designed, spec-driven ones from step 3: those are what find the gaps the tool's crude mutants miss.

## When the user's intent differs

If the user only wants tests written fast and says so, write good tests (step 5's rules), run 3-4 quick mutants, and mention in one line that a fuller check is available. Don't turn a five-minute request into an hour-long audit unasked.
