agentleFS
jocarrdjocarrd/crux-agents/skills/write-tests/SKILL.md

write-tests

Skill4 starsChanged 17 days agoMITView on GitHub

Write tests worth having: choose what deserves coverage and what doesn't, decide when the test goes before the code, cover the painful case before the happy one, keep them deterministic and validate them in the negative. Use when tests have to be added to something that has none, when you add new behaviour, when you fix a bug and want it not to come back, when you are about to refactor something with no safety net, or when asked to raise coverage.

76 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use close-spec, design-with-images 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.
  • dzhngSkill

    close-spec

    When a spec under specs/<feature>/ is done shipping (a write-spec build, or any planned task that produced a spec), archive it to specs/done/ and rewrite it from a build-plan into a durable rationale — the why, the principles, the invariants — pointing back to the real code for the how. Use when implementation has landed and the plan no longer matches what shipped, or the user says a feature/spec is finished. Pairs with [write-spec](../write-spec/SKILL.md) (the plan this closes) and [review](../review/SKILL.md) (run before closing).

    Also in 5 projects that use this

  • dzhngSkill

    design-with-images

    Explore UI and visual design with image generation, then iterate the real implementation against the user-selected concept. Use when brainstorming visual directions, offering mockup variants, or implementing an approved generated design; do not stop at the mockups or the first code approximation.

    Also in 5 projects that use this

  • transitive-bullshitSkill

    compare-screenshots

    Compare screenshots against the intended design, distinguishing approved references from historical baselines. Use for iterative implementation matching, before/after visual review, objective image telemetry, or checking a lone capture for flat, empty, or badly framed content.

    Also in 5 projects that use this

  • LucasMatuszewskiSkill

    audit-agents

    Audit and maintain agent configuration files (.claude/agents, AGENTS.md, CLAUDE.md, agent-memory). Checks for duplicates, outdated info, naming conflicts, wrong technical facts, and files over 200 lines. Fixes all issues and commits.

    Also in 5 projects that use this

  • wolverin0Skill

    audit-decisions

    Standardize remediation decisions, baseline-policy entries, and legal-review banners for accepted, deferred, or policy-blocked audit findings.

    Also in 4 projects that use this

  • rhnfzlSkill

    explore-unknowns

    Walk the user through mapping the unknowns of a task before, during, and after they build it, and hand them a four-quadrant map (settled ground, open decisions, taste, and landmines) they keep. Reach for this eagerly whenever a request is ambiguous or underspecified, the codebase or domain is unfamiliar, the user will "know it when they see it", a reference implementation must be understood before porting, a build-queue or architecture-changing task is about to start, a mid-build deviation needs capturing, or a finished change needs buy-in or verified understanding before merge. Trigger even when the skill is not named: "do a blindspot pass", "find my unknown unknowns", "interview me about this change", "brainstorm the approach for a task I am about to build", "help me scope this", "what am I missing here", "plan this before I build", "I know nothing about X in this codebase". When a territory profile is present it reads memory and the graph first and feeds the map into the build pipeline; without one it degrades to a plain general map. Not for trivial or mechanical tasks with clear acceptance criteria, single-fact lookups, pure debugging of a known symptom, or pure code review, those have their own tools. Do not use it to run the build itself; the map is the deliverable and implementation remains a separate task, whether it has not started or is already underway.

    Also in 5 projects that use this

  • +5 more from dzhng

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 71 edited versions we read keep these.

  • 8

    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:

    If you are only going to write three tests, make them from here.

    line 56
  2. Distinctive:

    After writing it: deliberately break what it tests, check that the test goes red for the right reason (not because of some other error), …

    line 78
  3. Distinctive:

    Before building the scaffolding, try extracting the pure logic and testing that.

    line 89
  4. Distinctive:

    Do they pass in random order and in parallel?

    line 105
  5. Distinctive:

    Do they pass on a clean machine, without your cache or your database?

    line 106
  6. Distinctive:

    Testing the implementation instead of the behaviour: If the test breaks on every refactor without anything observable changing, it is badly …

    line 111
  7. Distinctive:

    One giant test that tests everything: When it fails you don't know what failed.

    line 113
  8. Distinctive:

    Doubles that return whatever suits the test: If the double doesn't look like the real response, the test passes and production fails.

    line 117

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

write-tests

Writing tests is easy. Writing the ones worth having is not. The reason behind when the test goes first: <this-skill-directory>/references/why.md.

The criterion: test what hurts if it fails

You don't test for coverage, you test for consequence. Before writing a test, ask what happens if that breaks in production and nobody notices.

Deserves a testDoesn't
Calculations with business rulesGetters, trivial mappings
Transformation of external dataA framework doing what it promises
Edge cases and boundary valuesA constant having the value it has
Every bug that has already happened oncePrivate implementation details
Contracts between modules or servicesLayout, unless it is measurable
Logic a refactor is going to moveCode that will be gone next week

One test per real bug. It is the rule with the best return there is: the bug already proved that path breaks, so the probability of it coming back is not theoretical.

When the test goes first

Two cases, and only these two:

  • A bug that can be reproduced. First the test that fails because of the bug, then the fix.
  • Logic whose contract is known before the code: a calculation, a parser, a validation, a conversion between formats. You know what goes in and what has to come out, so write that down first.

It goes red for the reason you expect before writing the code: a red caused by an import or a typo proves nothing.

Everything else (exploring an approach, an interface still taking shape, glue code) is written first and tested afterwards, with the criterion above.

Start with the painful case

The happy path is usually covered incidentally by use. What nobody tests is the rest:

  • Empty, null, zero, empty string, empty list.
  • The maximum and the minimum, and one past each.
  • Malformed input, in the wrong format, with accents, very long.
  • Duplicates, reverse order, concurrency.
  • The external service's error: timeout, 500, a response with a changed shape.

If you are only going to write three tests, make them from here.

A test has to be deterministic

A test that fails one time in twenty is worse than not having it: it teaches the team to retry without looking, and the day it fails for real nobody will believe it.

The four sources of nondeterminism, and what to do about them:

SourceWhat to do
Time and datesInject the clock, never read it inside the logic
RandomnessFixed seed, or inject the generator
Network and external servicesDoubles with fixed responses; the fixture is the contract
Execution order and shared stateEach test creates and destroys its own

Validate it in the negative

A test you have never seen fail is worthless. It is the most common mistake and the most expensive, because it produces false confidence.

After writing it: deliberately break what it tests, check that the test goes red for the right reason (not because of some other error), and revert. Thirty seconds that tell you whether the safety net exists. If it went red before the code, as in the test-first cases, this is already done.

What to do when it is hard to write

A test that is hard to write is almost never a problem with the test: it is the design giving a warning. If you need to simulate five dependencies to test one function, that function does five things.

Before building the scaffolding, try extracting the pure logic and testing that. The part that talks to the world stays thin and logic-free, and stops needing complicated tests.

Names

The test name is the first thing read when it fails in a log, months later. Make it state the condition and the expectation, not the function name:

  • Bad: test_calculate, it("works")
  • Good: returns zero when the list is empty, rejects the date if the end is before the start

Before accepting a batch

  • Does any fail if I deliberately break what they test?
  • Do they pass in random order and in parallel?
  • Do they pass on a clean machine, without your cache or your database?
  • Is any so slow that people will start skipping them?

Anti-patterns

  • Testing the implementation instead of the behaviour. If the test breaks on every refactor without anything observable changing, it is badly written.
  • One giant test that tests everything. When it fails you don't know what failed.
  • Too many assertions. Checking twenty fields just in case turns any legitimate change into a broken test.
  • Doubles that return whatever suits the test. If the double doesn't look like the real response, the test passes and production fails.
  • Writing tests to raise a number. Coverage is a signal, not a goal. You can have 90% and test nothing that matters.

Related

  • /ship: gates 1 and 5, which are these tests
  • /root-cause: before writing the test for a bug, understand the bug
  • /explain-plan: the plan's review focus says which failures no test covers

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.