Worked example · Testing

Raising test coverage with WDD, without junk tests

Coverage alone is a bad WDD verifier: an agent will write tests that run code without checking it. Pair the coverage target with a mutation score, and the loop produces tests that would actually catch bugs.

The goal

Raise line coverage of the billing module from 41% to 85% with tests that would catch real regressions.

The verifier

The coverage report for the module, plus a mutation testing run (for example Stryker or mutmut) with a minimum mutation score.

Why this check: Coverage says the code ran; the mutation score says the tests noticed when it was broken.

The set-up

  • Coverage and mutation tools wired to one command that prints both numbers.
  • A rule that application code may not change (tests only), unless a real bug is found, which goes to NOTES.md.

The kickoff prompt

Kickoff

Raise coverage of src/billing to at least 85% and its mutation score to at least 70%. Write tests only; if you find a bug, write a failing test for it and note it in NOTES.md, do not fix it. Each round: run the report, take the least covered file, test it properly. Keep going until both targets are met.

How the rounds went

Rounds 1 to 4
Coverage climbs to 70%, but the mutation score sits at 38%: the new tests barely assert anything. The push says so with the surviving mutants listed.
Rounds 5 to 10
The agent rewrites tests to check results and edge cases. Two real rounding bugs turn up as failing tests.
Round 11
87% coverage, 74% mutation score, two bugs documented for a person to fix.

What worked

  • A second number that cannot be gamed the same way as the first.
  • Keeping the agent out of application code, so found bugs became evidence rather than silent changes.

What to watch for

  • Mutation testing is slow. Run it on the files changed in the round, and on the whole module at the end.

Build a kit for a task like this

A worked example written to show the method, not a report of a specific project.

Questions people ask

Should the agent fix the bugs it finds?

Not in the same loop. A failing test plus a note lets a person decide; mixing "add tests" and "change behaviour" makes the result hard to review.

More examples