agentleFS
ATOM00blueATOM00blue/agent-skills-pro/skills/test-writer/SKILL.md

test-writer

Skill0 starsChanged 6 months agoMITView on GitHub

Writes focused, behavior-driven unit and integration tests for a given function, module, or change, covering happy paths, edge cases, and error conditions using the project's existing test framework and conventions. Use when the user asks to write or add tests, improve coverage, write a unit/integration test, or do test-driven development.

28 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use debug-fix, debugger and 8 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.
  • zebbernSkill

    debug-fix

    Find and fix a bug or issue — from any source (GitHub issue, error message, user report, or observed behavior)

    Also in 4 projects that use this

  • JohnJBorenSkill

    debugger

    Systematic debugging workflows, root cause analysis, and troubleshooting patterns

    Also in 3 projects that use this

  • get-proofpilotSkill

    context-budget

    Audits Claude Code context window consumption across agents, skills, MCP servers, and rules. Identifies bloat, redundant components, and produces prioritized token-savings recommendations.

    Also in 3 projects that use this

  • nimbalystSkill

    prd-writer

    Create structured Product Requirements Documents (PRDs) with prioritized requirements. Use when writing product specs, feature requirements, or project briefs.

    Also in 3 projects that use this

  • GoogleSkill

    code-reviewer

    Also in 4 projects that use this

  • GitHubSkill

    refactor

    Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 27 edited versions we read keep these.

  • 6

    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:

    Write tests that document behavior and catch regressions — not tests that just chase a coverage number.

    line 13
  2. Distinctive:

    Follow the existing file location, naming, and assertion style.

    line 35
  3. Distinctive:

    Prefer a few high-value cases over many trivial ones.

    line 52
  4. Distinctive:

    No real network, clock, randomness, or filesystem unless that *is* the unit under test — inject or mock them.

    line 64
  5. Distinctive:

    Run the suite. A test that can't fail is worthless: if unsure, temporarily break the code and confirm the test goes red, then restore it.

    line 73
  6. Distinctive:

    Integration tests: use an ephemeral DB/container or transaction rollback per test for isolation.

    line 131

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

Test Writer

Write tests that document behavior and catch regressions — not tests that just chase a coverage number. Match the project's existing framework and style.

Workflow

- [ ] 1. Detect the test framework and conventions already in use
- [ ] 2. Identify the unit under test and its observable behavior
- [ ] 3. Enumerate cases: happy path, edges, errors, boundaries
- [ ] 4. Write each test: Arrange–Act–Assert, one behavior per test
- [ ] 5. Make tests deterministic and isolated
- [ ] 6. Run them; ensure they pass and actually exercise the code

Step 1 — Match the project

Do not introduce a new test framework. Detect and reuse what exists:

  • JS/TS: vitest, jest, node:test, mocha (check package.json and existing *.test.*).
  • Python: pytest (default), unittest.
  • Go: testing + table-driven tests.
  • Rust: #[cfg(test)] modules; Java: JUnit 5.

Follow the existing file location, naming, and assertion style. Reuse existing fixtures and helpers instead of inventing parallel ones.

Step 2 — Test behavior, not implementation

Assert on observable outputs and side effects (return values, thrown errors, emitted events, DB rows) — not private internals. A good test survives a refactor that preserves behavior.

Step 3 — Enumerate cases

For each unit, cover:

  • Happy path: typical valid input → expected output.
  • Boundaries: empty, single element, max size, zero, negative, off-by-one.
  • Edge values: null/undefined/None, empty string, whitespace, unicode, very large input.
  • Error conditions: invalid input raises/returns the right error; failures are handled.
  • State/idempotency: calling twice, ordering, concurrency where relevant.

Prefer a few high-value cases over many trivial ones. Every test should be able to fail for a real reason.

Step 4 — Structure each test

  • Arrange–Act–Assert with a blank line between phases.
  • One behavior per test. Multiple assertions are fine if they describe the same behavior.
  • Descriptive names that read as a sentence: returns 0 for an empty cart, throws when the user is not found.

Step 5 — Determinism and isolation

  • No real network, clock, randomness, or filesystem unless that is the unit under test — inject or mock them. Freeze time; seed RNG.
  • Each test sets up and tears down its own state; tests must pass in any order and in parallel. No shared mutable globals.
  • Mock at the boundary (HTTP client, DB driver), not your own domain logic. Over-mocking produces tests that pass while the app is broken.

Step 6 — Verify

Run the suite. A test that can't fail is worthless: if unsure, temporarily break the code and confirm the test goes red, then restore it.

Examples

Vitest / TypeScript for function discount(total, code):

import { describe, it, expect } from "vitest";
import { discount } from "./pricing";

describe("discount", () => {
  it("applies a known 10% code", () => {
    expect(discount(100, "SAVE10")).toBe(90);
  });

  it("returns the original total for an unknown code", () => {
    expect(discount(100, "NOPE")).toBe(100);
  });

  it("never returns a negative total", () => {
    expect(discount(5, "SAVE10")).toBeGreaterThanOrEqual(0);
  });

  it("throws on a negative total", () => {
    expect(() => discount(-1, "SAVE10")).toThrow(/total/i);
  });
});

pytest table-driven style:

import pytest
from app.pricing import discount

@pytest.mark.parametrize("total, code, expected", [
    (100, "SAVE10", 90),     # happy path
    (100, "NOPE", 100),      # unknown code -> no change
    (0, "SAVE10", 0),        # boundary: zero total
])
def test_discount(total, code, expected):
    assert discount(total, code) == expected

def test_discount_rejects_negative_total():
    with pytest.raises(ValueError, match="total"):
        discount(-1, "SAVE10")

Anti-patterns to avoid

  • Asserting on log output or call counts instead of real behavior.
  • Tests coupled to implementation details (private methods, internal call order).
  • One giant test covering ten things — failures become undiagnosable.
  • Snapshot tests for logic that should have explicit assertions.
  • Mocking the thing you're trying to test.

Common edge cases

  • Async code: await/return promises; assert on rejections; avoid arbitrary sleep.
  • Time-dependent logic: inject a clock or use fake timers; never assert on now().
  • Floating point: compare with a tolerance, not ==.
  • Integration tests: use an ephemeral DB/container or transaction rollback per test for isolation; keep them separate from fast unit tests.

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.