agentleFS
rdokrdok/unit-test-skill/SKILL.md

unit-test

Skill0 starsChanged 4 months agoMITView on GitHub

Ensures every source file edit has a corresponding unit test — writing one if missing, extending one if the changed behaviour is uncovered. Apply automatically when creating, editing, implementing, fixing, refactoring, or modifying any function, class, component, handler, service, or module.

8 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 5

    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:

    When any code change is made, follow this checklist before marking the task done:

    line 11
  2. Distinctive:

    Check for an existing test file covering that unit.

    line 14
  3. Distinctive:

    If no test exists → write one.

    line 15
  4. Very specific:

    No comments inside tests either — the it(...) sentence is the documentation.

    line 45
  5. Distinctive:

    Before marking any test done:

    line 56
  6. Distinctive:

    Write the failing test first (it must fail before the fix).

    line 69

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

Unit Test Skill

When any code change is made, follow this checklist before marking the task done:

  1. Identify the unit(s) of code that changed (function, class, or module).
  2. Check for an existing test file covering that unit.
  3. If no test exists → write one. If a test exists but misses the changed behaviour → add a case.

Philosophy

London School TDD with strict Osherove AAA — makeFactory() owns the entire Arrange phase, mock<T>() replaces every collaborator, one expect() per test.

See reference/principles.md for detailed rules, worked examples, and the fallback reasoning source for any case not explicitly covered here.


No code comments — a comment is a missing test title

Production code (and test code) carries no explanatory comments. Anything you would write as a comment to describe what the code does or why it behaves a certain way must instead be expressed as a test title — a behavioural spec that asserts that behaviour.

Why: a code comment is static prose that silently drifts out of sync with the code — nothing fails when it becomes wrong, so it rots. A test title is living documentation: it is bound to an assertion, so if the behaviour changes the test goes red. The docs cannot go stale, because the suite enforces them.

  • Tempted to write // falls back to eu-west-1 when no region is set? Delete it and write it("falls back to eu-west-1 when no region is set", ...).
  • A comment explaining a branch is a signal that the branch lacks a named test. Add the test and let its title carry the intent.
  • No comments inside tests either — the it(...) sentence is the documentation.

The only permitted comment is an irreducible external constraint that no test can express — e.g. a link to an upstream bug the code works around, or a regulatory/protocol note. It is rare (~1%); when you reach for one, add it and flag it for a decision, never silently.


Test quality checklist

Before marking any test done:

[ ] Test describes behaviour, not implementation
[ ] Test calls makeFactory() and destructures only what it needs
[ ] Test has exactly one expect()
[ ] No code comments anywhere — intent lives in test titles, not prose

Regression tests for bug fixes

  1. Write the failing test first (it must fail before the fix).
  2. Fix the bug.
  3. Confirm the test now passes.
  4. The test is the bug's permanent tombstone — never delete it.

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.