agentleFS
sitsit/agent-skills/skills/writing-tests/SKILL.md

writing-tests

Skill0 starsChanged 8 days agoMITView on GitHub

Write and change tests that pin behavior, survive refactors, and fail for the right reason — TDD cycle, test layout, fixture builders, naming, determinism, mock policy, verification scope. Use when writing new tests, fixing or explaining a failing test, deciding what to test, reviewing test coverage, or changing code that has tests; also when the user asks to "add tests" or "cover this case".

52 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use reviewing-code, running-tests and 9 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.
  • ZayZay1nonlySkill

    reviewing-code

    Provides structured code review with prioritized feedback. Use when reviewing PRs, analyzing code quality, checking for bugs, or auditing changes. Triggers on "review this", "check this code", PR reviews, or code quality questions.

    Also in 5 projects that use this

  • OpenAISkill

    running-tests

    Guide for running tests in the openai-dotnet repository. Use this when asked to run, debug, or validate tests, or when writing new tests. Explains test modes (Playback, Record, Live), how to identify recorded vs non-recorded tests, environment variable configuration, and what to do when recordings are missing or stale.

    Also in 4 projects that use this

  • JetBrainsSkill

    commits

    Read before each commit, amend or reword: the subject SafePush accepts and the body.

    Also in 3 projects that use this

  • BlockSkill

    debugging

    Debugging guidelines and best practices

    Also in 5 projects that use this

  • sahinSkill

    execute

    Also in 3 projects that use this

  • MicrosoftSkill

    council

    Convene the persona panel — six orthogonal review lenses — on a target. Cold independent fan-out, debate-to-consensus, synthesized verdict with recorded dissent and a roster manifest.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

12 rules. 0 are common, 11 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 52 edited versions we read keep these.

  • 11

    Distinctive

    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:

    Red: write tests that specify the required behavior without over-constraining the implementation.

    line 16
  2. Distinctive:

    Green: write just the code that makes them pass.

    line 19
  3. Distinctive:

    Never restate the implementation or pin an arbitrary fixed configuration.

    line 30
  4. Distinctive:

    Keep the call under test visible.

    line 70
  5. Distinctive:

    Prefer production enums and constants when they define the tested value.

    line 87
  6. Distinctive:

    Use real entities and value objects when setup is small.

    line 88
  7. Very specific:

    Leave self-evident structural values inline — an initial 0, a single boundary + 1, a length of 2 after two explicit additions.

    line 106
  8. Distinctive:

    When production behavior is relative to the current time, capture it once.

    line 116
  9. Distinctive:

    When a change alters what a function returns or prints, run its tests and its callers', and update the assertions and test data that pin …

    line 123
  10. Distinctive:

    Update contract tests when the contract changes.

    line 126
  11. Distinctive:

    Run the narrowest check that covers the change: the tests of the changed code and its callers.

    line 128
  12. Distinctive:

    When the code does not show a reported failure's cause, reproduce it once before fixing, so the fix addresses the failure, not the report.

    line 132

“Common” is measured: kept by at least 6 in 10 of the 52 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

writing-tests

A test specifies behavior: it fails when the behavior breaks and passes when it holds. Tests that restate the implementation add noise; tests that pin arbitrary configuration add drag; tests that survive a real bug add nothing.

The cycle

Develop features and bug fixes in red-green-refactor cycles:

  • Red: write tests that specify the required behavior without over-constraining the implementation. Watch each fail and read the failure: a test that passes before the code exists specifies nothing.
  • Green: write just the code that makes them pass.
  • Refactor: review the code for maintainability, then the tests: what would a reviewer reading only the diff conclude?

What a test asserts

Assert on public behavior: domain outcomes and state the caller can observe.

  • Design each test around a realistic regression: what plausible consumer-visible bug does it catch? Wiring, pure echoes, source text, incidental defaults, bare not-throwing, and "the list grew" are not bugs. Never restate the implementation or pin an arbitrary fixed configuration.
  • Cover the complementary outcomes of each branch under test.
  • The name states the scenario and expected result, so it tells a reviewer what broke; the assertions fully support what the name claims.
  • Assert on content, not on shape the implementation chose. Over a shared fixture, assert on the text or ids the test cares about, so extending the fixture breaks no test that does not care about the extension. Pin positions, counts and times only for data the test builds itself.
  • Assert so a failure names what differs: compare values or project the properties under test, never a boolean computed from them. Use the assertion library's matchers to write the most expressive tests.
  • Characterization tests are temporary regression protection for behavior that lacks a practical behavioral test boundary. Keep them to stable semantics tied to a concrete behavior or past regression, and mark the group with a short comment stating the limitation and the boundary that should replace them.

What not to test

Skip argument parsing, pass-through to external tools, getters and setters, and anything the type checker or compiler already proves. Coverage is not a target; a module with no decisions in it needs no test file.

Where tests live

  • A module's unit tests sit at its path: pipeline/pack.py is tested in tests/pipeline/pack/. Moving a module moves its tests; either path finds the other.
  • One test file per responsibility of the unit under test, named for the unit and that responsibility, so tools and readers pair it with its subject. Integration tests carry a name the runner can select apart.
  • Shared helpers — builders, constants, fake backends — live once, in tests/support/, never copied between test files.
  • End-to-end tests sit outside the per-module tree: they test the product, not a module.

Arrange–Act–Assert, visibly

  • Each test reads as arrange, act, assert: the setup, the one call under test, and what follows from it.
  • Keep the call under test visible. Helpers may build or persist fixtures; they must not hide the query, command, or result being asserted, or the test cannot be read without reading the helper.
  • One behavior per test. Two assertions on one outcome are fine; a second act is a second test.
  • Elaborate setup — many mocks, many arguments — signals a design fault: fix the design, not the test.
  • Comments explain what name and code cannot: non-obvious domain constraints, fixture techniques, test-boundary decisions.

Fixtures and builders

  • Fluent builders construct fixture data: a base builder holds suite-wide invariants; each test sets its scenario values visibly.
  • Helpers cut noise and duplication; name them so tests read fluently. Noun helpers return objects for composition; helpers that persist or change state are verbs.
  • Prefer production enums and constants when they define the tested value.
  • Use real entities and value objects when setup is small. Fake or mock external, expensive, or independently tested collaborators, keeping the decision logic real. Verify interactions only when the interaction is the contract.
  • Build values that production receives in raw or projected form through one shared conversion helper; per-test hand-assembled copies drift from what production actually sends.

Naming values

  • Name fixture values — numbers, strings, dates, identifiers — that carry scenario meaning, connect setup to assertion, or participate in a relationship. Prefer a test-local value; use a shared constant only for a suite invariant or shared fixture default. Once a second value competes, the test names its own.
  • Derive related values from one named basis (last_year = year - 1); name independent states separately rather than inventing arithmetic between them.
  • Leave self-evident structural values inline — an initial 0, a single boundary + 1, a length of 2 after two explicit additions; extracting them hides the structure. Do not extract irrelevant filler just to remove literals.

Determinism and time

  • One time anchor per behavior; derive scenario times from the interval or threshold under test. Use the production constant when it defines the contract; otherwise name the threshold in the test.
  • When production behavior is relative to the current time, capture it once; otherwise use a fixed anchor or an injected clock.
  • A test passes alone and in the suite, in any order and any timezone. No test reads the wall clock, the network, or another test's state.

Changing code that has tests

  • When a change alters what a function returns or prints, run its tests and its callers', and update the assertions and test data that pin the old output or shape.
  • Update contract tests when the contract changes. Delete tests that pin wording or implementation details, whoever wrote them; never re-pin them.
  • Run the narrowest check that covers the change: the tests of the changed code and its callers. Run the whole suite only when nothing narrower answers, and once before push — by the pre-push hook, where the repo has one.
  • When the code does not show a reported failure's cause, reproduce it once before fixing, so the fix addresses the failure, not the report.

references

  • references/examples.md — worked examples: builders, constants vs local values, conversion helpers, time anchors, fakes vs mocks, assertions over shared fixtures.

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.