agentleFS
VelimirMuellerVelimirMueller/ai-development-skills/skills/craft/write-clean-tests/SKILL.md

write-clean-tests

Skill7 starsChanged 15 days agoMITView on GitHub

Use when writing or reviewing tests — F.I.R.S.T. properties, one concept per test, state coverage not line coverage, and a regression test for every bug fix.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the tests for three failures: tests that mirror the implementation (they break on every refactor and catch nothing), tests with …

    line 26
  2. Distinctive:

    Test the public behaviour, not the private shape.

    line 34
  3. Very specific:

    Use the arrange/act/assert shape.

    line 36
  4. Distinctive:

    Use real data (and a synthetic edge case) over an exhaustive mock of reality.

    line 49

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Write Clean Tests

Tests are first-class code: they must be as readable as production and must fail for the right reason. Production testing boundary is set by engineering-principles.md.

F.I.R.S.T.

  • Fast — a slow suite stops being run. Keep unit tests in memory; push the slow ones out of the unit layer.
  • Independent — one test must not depend on another's order or state; run them in any order.
  • Repeatable — same result in any environment; no flakiness from time, network or shared state.
  • Self-validating — a boolean pass/fail, never a human reading the output.
  • Timely — written just before or with the production code, not weeks later.

1. Audit (change nothing)

cat .claude/stack-profile.md 2>/dev/null | head -20
find . \( -name "*_test.*" -o -name "*_spec.*" -o -name "*.test.*" -o -name "*.spec.*" -o -name "*Test.*" -o -name "*Tests.*" -o -name "test_*.*" -o -path "*__tests__*" \) 2>/dev/null | head -20

Read the tests for three failures: tests that mirror the implementation (they break on every refactor and catch nothing), tests with several unrelated asserts (one failure hides another), and tests that assert internals instead of behaviour.

2. One concept per test

  • One assert per behaviour, one concept per test. A test named "it works" asserts nothing; name it "returns zero when the list is empty".
  • Test the public behaviour, not the private shape. A test coupled to internals fails when the code improves.
  • Use the arrange/act/assert shape; keep the arrange minimal so the reader sees the one thing under test.

3. State coverage over line coverage

  • Cover the states and transitions that pay (the boundary conditions, the error paths, the money path), not a percentage. A line covered is not a bug caught.
  • Saboteur-test the tests: break the production code and confirm a test fails — a test that cannot fail tests nothing.

4. A regression test for every fix

  • A bug is a missing test. Write the test that fails on the old code, then the fix — the test is the proof the bug cannot return.
  • Use real data (and a synthetic edge case) over an exhaustive mock of reality.

Verify

pnpm test (or the profile's runner) is green, each test states one behaviour, and breaking the code under test fails exactly one test with a message that names the cause. State the new coverage in the note.

When to deviate

  • A prototype with a one-week life: a couple of smoke tests, not a full suite.
  • A bug cheap to fix and loud (an internal dashboard): a thin regression test is enough.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.