agentleFS
swestfall21swestfall21/claude-skills/test-discipline/SKILL.md

test-discipline

Skill0 starsChanged 4 months agoMITView on GitHub

What makes a test worth having — test behavior not implementation, cover the case that motivated the change, mock sparingly. Use when writing tests, reviewing tests, or deciding what to test.

15 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use squad-commands, architectural-proposals and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Microsoft AzureSkill

    squad-commands

    Categorized catalog of common Squad operations. Coordinator reads this file and presents it as an interactive menu when the user asks for available commands or help.

    Also in 4 projects that use this

  • Microsoft AzureSkill

    architectural-proposals

    How to write comprehensive architectural proposals that drive alignment before code is written

    Also in 3 projects that use this

  • +10 more from Azure

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 7 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 13 edited versions we read keep these.

  • 7

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never mock the thing under test, and don't mock what you can use for real — pure functions, in-memory implementations, local files.

    line 23
  2. Distinctive:

    If a test needs five mocks to instantiate the subject, that's design feedback about coupling — worth reporting, not muffling with more …

    line 25
  3. Distinctive:

    Prefer assertions whose failure output shows the actual vs.

    line 30
  4. Distinctive:

    Do not write a fix's test without seeing it fail against the unfixed code.

    line 39
  5. Distinctive:

    Do not assert on implementation details a refactor would legitimately change.

    line 40
  6. Distinctive:

    Do not mock the system under test.

    line 41
  7. Distinctive:

    Do not delete or skip a failing test to make a suite green — that is falsifying the report.

    line 42

“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “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

Test discipline

Tests are not a quota to fill; they are executable claims about behavior. A good test fails when the behavior breaks, passes when it doesn't, and tells you what went wrong when it fails. Everything else follows from that.

Test behavior, not implementation

  • Assert on what the code does — outputs, state changes, observable effects — not on how it does it (which private method ran, in what order, with what internal arguments).
  • A test that breaks on a refactor that preserved behavior is a bad test: it punishes exactly the maintenance work tests exist to enable.
  • Name the test after the behavior it claims: rejects_expired_tokens, not test_validate_2.

Cover the motivating case

  • The first test for any change is the case that motivated it: the bug's reproduction, the feature's core promise. If the change is a fix, the test must fail without the fix — run it both ways once to prove it.
  • Then the edges the change creates: the empty input, the boundary value, the error path, the concurrent caller — chosen because the changed code makes them reachable, not from a generic checklist.

Mock sparingly

  • Never mock the thing under test, and don't mock what you can use for real — pure functions, in-memory implementations, local files.
  • Mock at system boundaries: the network, the clock, the payment provider. A test whose every collaborator is fake verifies your mocks agree with each other, not that the code works.
  • If a test needs five mocks to instantiate the subject, that's design feedback about coupling — worth reporting, not muffling with more mocks.

Make failures readable

  • One behavior per test, so a failure names the broken behavior rather than "something in this 40-assertion test."
  • Prefer assertions whose failure output shows the actual vs. expected values.
  • A test the next engineer can't understand will be deleted or ignored the first time it fails inconveniently.

Coverage is a byproduct, not a goal

Chasing a percentage produces assertion-free tests that execute lines without checking anything. Coverage is useful for finding untested code; it says nothing about whether the tested code is tested well.

Non-negotiables

  • Do not write a fix's test without seeing it fail against the unfixed code.
  • Do not assert on implementation details a refactor would legitimately change.
  • Do not mock the system under test.
  • Do not delete or skip a failing test to make a suite green — that is falsifying the report.

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.