agentleFS
Kuan-AI-comKuan-AI-com/agent-skills/skills/write-tests/SKILL.md

write-tests

Skill0 starsChanged 6 days agoMITView on GitHub

Write unit or integration tests for a function, module, endpoint or bug fix, in the project's existing test framework. Use when the user says "add tests", "write tests for this", "increase coverage", "test this bug fix", or "why isn't this tested".

79 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, 7 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 74 edited versions we read keep these.

  • 7

    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. Very specific:

    Test command: package.json scripts, Makefile, pyproject.toml/pytest.ini/tox.ini, go.mod, Cargo.toml, CI config in .github/workflows/.

    line 10
  2. Distinctive:

    Run the existing suite (or the relevant file) once before writing, so you know the baseline.

    line 12
  3. Distinctive:

    Read the function and its callers.

    line 16
  4. Distinctive:

    Write a short list, then implement:

    line 20
  5. Distinctive:

    Avoid large snapshots; they get approved without being read.

    line 34
  6. Distinctive:

    Run the new test file first, then the whole affected suite.

    line 42
  7. Distinctive:

    If a test fails because the code is wrong, do not change the assertion to match.

    line 43
  8. Distinctive:

    Do not modify production code just to make it testable without saying so and why.

    line 44

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

1. Find how this project tests

  • Test command: package.json scripts, Makefile, pyproject.toml/pytest.ini/tox.ini, go.mod, Cargo.toml, CI config in .github/workflows/. Use that command, not a guessed one.
  • Find the nearest existing test for similar code and copy its location, naming, imports, fixtures, factories and mocking style. Do not add a new framework or assertion library.
  • Run the existing suite (or the relevant file) once before writing, so you know the baseline. If it is already red, tell the user before adding to it.

2. Read the code under test

Read the function and its callers. The behaviors worth testing are what callers rely on: return values, thrown errors, side effects (DB writes, events, calls to other services). Not private helpers or the order of internal calls.

3. Plan cases before coding

Write a short list, then implement:

  • the main path with realistic input
  • boundaries that matter for this code: empty, one, many, max length, zero, negative, missing optional fields, duplicates
  • error paths: invalid input, dependency failure or timeout, permission denied
  • for a bug fix: the exact input from the bug report

Skip cases that only re-test the language or a library.

4. Write them

  • One behavior per test; name it as a sentence: "rejects an expired coupon".
  • Arrange / act / assert, visible in the test. Prefer explicit expected values over recomputing them with the same logic as the code.
  • Mock only boundaries you do not control: network, clock, randomness, third-party APIs. Use the project's real DB test setup if it has one.
  • Deterministic: freeze time, seed randomness, no reliance on test order or shared mutable state, no real sleeps.
  • Avoid large snapshots; they get approved without being read.

5. Prove each test can fail

A test that cannot fail is worse than none. For each new test, break the behavior (flip a condition, return early, comment out the fix) and confirm the test goes red, then restore. For bug-fix tests, confirm it fails without the fix.

6. Run and report

  • Run the new test file first, then the whole affected suite. Show the command and the pass/fail counts.
  • If a test fails because the code is wrong, do not change the assertion to match. Report: "this looks like a bug: <input> gives <actual>, expected <expected>", and ask before fixing production code.
  • Do not modify production code just to make it testable without saying so and why.

Summary at the end: which behaviors are now covered, which you deliberately left out, and any bugs found.

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.