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
- DataDog/browser-sdktheir own version, first seen Nov 30, 2026
- basaltbytes/skillstheir own version, first seen Nov 29, 2026
- mattwynne/skillstheir own version, first seen Nov 29, 2026
- dayfinggg/openai-codex-agent-skillstheir own version, first seen Nov 29, 2026
- borkweb/skillstheir own version, first seen Nov 29, 2026
- 851-labs/codevisortheir own version, first seen Nov 29, 2026
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.
ZayZay1nonlySkillreviewing-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
OpenAISkillrunning-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
JetBrainsSkillcommits
Read before each commit, amend or reword: the subject SafePush accepts and the body.
Also in 3 projects that use this
BlockSkilldebugging
Debugging guidelines and best practices
Also in 5 projects that use this
sahinSkillexecute
Also in 3 projects that use this
MicrosoftSkillcouncil
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
Other versions52 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 52
- remotion-dev/remotion★ 76ksame name
- PostHog/posthog★ 41ksame name
- JetBrains/intellij-community★ 21ksame name
- quarkusio/quarkus★ 16ksame name
- mcp-use/mcp-use★ 11ksame name
- DetachHead/rebased★ 6.6ksame name
- chattocorp/chatto★ 3ksame name
- starkware-libs/cairo★ 1.9ksame name
- bholmesdev/hubble.md★ 1.5ksame name
- amplifthq/openmeld★ 1.4ksame name
42 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository2 other files it gives its agents.
- commit-disciplineSkill
- repo-setupSkill
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
- Distinctive: line 16
Red: write tests that specify the required behavior without over-constraining the implementation.
- Distinctive: line 19
Green: write just the code that makes them pass.
- Distinctive: line 30
Never restate the implementation or pin an arbitrary fixed configuration.
- Distinctive: line 70
Keep the call under test visible.
- Distinctive: line 87
Prefer production enums and constants when they define the tested value.
- Distinctive: line 88
Use real entities and value objects when setup is small.
- Very specific: line 106
Leave self-evident structural values inline — an initial 0, a single boundary + 1, a length of 2 after two explicit additions.
- Distinctive: line 116
When production behavior is relative to the current time, capture it once.
- Distinctive: line 123
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 …
- Distinctive: line 126
Update contract tests when the contract changes.
- Distinctive: line 128
Run the narrowest check that covers the change: the tests of the changed code and its callers.
- Distinctive: line 132
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.
“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.
Files
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.pyis tested intests/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 of2after 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.
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
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.

