agentleFS
Lethe044Lethe044/agentskill-kit/skills/unit-test-writer/SKILL.md

unit-test-writer

Skill50 starsChanged 21 days agoMITView on GitHub

Writes focused unit tests for a function or module, covering the normal case, edge cases and failures, in the test framework the project already uses. Use when the user asks for tests, wants coverage for new code, or needs a regression test that reproduces a bug.

4 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

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

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 7

    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:

    Find the conventions: Look at existing tests for the framework (pytest, unittest, Jest, JUnit, Go test), file layout, naming and fixtures.

    line 23
  2. Distinctive:

    Plan the cases: before writing code:

    line 26
  3. Distinctive:

    Write the failing test first, from the report.

    line 40
  4. Distinctive:

    Do not copy the implementation into the test to compute the expected value.

    line 45
  5. Distinctive:

    Avoid sleeping, real network calls and shared global state.

    line 46
  6. Distinctive:

    Keep test data inline unless it is large.

    line 47
  7. Distinctive:

    If the code cannot be tested without a refactor (for example it reads a global), say so and propose the smallest change that makes it …

    line 56

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

Good tests describe behavior. They fail for one reason and say what broke.

When to use

  • New code has no tests.
  • A bug was fixed and needs a test that would have caught it.
  • The user asks to raise coverage on a module.

Steps

  1. Find the conventions. Look at existing tests for the framework (pytest, unittest, Jest, JUnit, Go test), file layout, naming and fixtures. Follow them. Do not introduce a new framework.
  2. Read the code under test. List its inputs, outputs, side effects and the errors it can raise.
  3. Plan the cases before writing code:
    • the normal case with realistic input,
    • boundaries: empty, one item, maximum, zero, negative, unicode,
    • invalid input and the exact error expected,
    • one case per branch that has different behavior.
  4. Write each test small. One behavior per test, a name that states it (test_returns_empty_list_for_empty_input), arrange, act, assert in that order.
  5. Isolate. Replace network, clock, randomness and the file system with fakes or temporary directories. Tests must not depend on the order they run in.
  6. Run them. Show the command and the result. Make sure a new test fails when the behavior is broken (change the code or the expectation briefly and check).

For a bug fix

Write the failing test first, from the report. Confirm that it fails for the right reason, then fix the code.

Rules

  • Assert on behavior, not on implementation details such as private function calls.
  • Do not copy the implementation into the test to compute the expected value. Use a literal.
  • Avoid sleeping, real network calls and shared global state.
  • Keep test data inline unless it is large.

Example

For parse_duration("1h30m") the plan is: "1h30m" gives 5400, "90s" gives 90, "" raises ValueError, "1x" raises ValueError, and "0s" gives 0.

Errors

If the code cannot be tested without a refactor (for example it reads a global), say so and propose the smallest change that makes it testable.

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.