agentleFS
patrick-fupatrick-fu/awesome-skills/write-unit-test/SKILL.md

write-unit-test

Skill66 starsChanged 2 months agoMITView on GitHub

Use when writing, reviewing, or improving unit tests for production business code, including regression, async, integration-boundary, and mock-heavy cases.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    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:

    Use this advisory skill for production product or business code.

    line 10
  2. Distinctive:

    Read the exported surface, its callers, nearby tests, and shared test utilities.

    line 15
  3. Distinctive:

    Write one test whose name states the expected outcome.

    line 18
  4. Distinctive:

    Run the focused test and relevant suite.

    line 27
  5. Distinctive:

    Prefer exact domain outcomes and meaningful fields.

    line 33
  6. Distinctive:

    Use a real dependency or small fake when its behavior matters.

    line 35
  7. Distinctive:

    Wait for the condition or event that proves async completion.

    line 38
  8. Distinctive:

    Keep contract-relevant fields in test doubles.

    line 40
  9. Distinctive:

    Treat private-state access as a coupling signal.

    line 44

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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 Unit Tests

Use this advisory skill for production product or business code. Prompt, skill, and agent-behavior evaluation need different methods.

Method

  1. Read the exported surface, its callers, nearby tests, and shared test utilities. State one caller-visible contract and the regression risk it guards.
  2. Write one test whose name states the expected outcome. Keep the decisive input visible at the call site; split distinct behaviors.
  3. Assert observable effects: returned values, public state, stable error types or codes, persistence, emitted events, rendered UI, or a boundary call when that call is itself the contract.
  4. Build the smallest realistic setup. Match real data and error shapes; isolate only the lowest true external boundary.
  5. For a regression or test-first change, confirm the test is red for the intended reason before relying on it.
  6. Run the focused test and relevant suite. Finish only when breaking the stated contract would fail the test while harmless internal refactoring would not.

Judgment

  • Prefer exact domain outcomes and meaningful fields. Use full snapshots or full error messages only when the entire representation is the contract.
  • Use a real dependency or small fake when its behavior matters. Mocks fit slow, flaky, costly, or external boundaries; verify collaborator calls only when the call is externally meaningful.
  • Wait for the condition or event that proves async completion. Use a controlled clock or fixed delay only when timing itself is the contract.
  • Keep contract-relevant fields in test doubles; partial mock shapes can hide downstream assumptions.
  • Let builders remove noise while exposing the value that makes the case meaningful.
  • Treat private-state access as a coupling signal. Keep test-only affordances in test utilities and production APIs product-driven.
  • Match the repository's existing framework, naming, placement, and helper conventions.

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.