agentleFS
mikejhillmikejhill/agent-skills/skills/test-design/SKILL.md

test-design

Skill0 starsChanged 3 days agoMITView on GitHub

Language-agnostic test design: one behavior per test, naming, assertions with diagnostics, isolation, test data, coverage, and anti-patterns. Use when writing, reviewing, or refactoring unit, integration, or end-to-end tests. Not for test runner or CI setup.

26 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use add-a-use-case, branches-and-pull-requests 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.
  • LeanMeanCleanAppsSkill

    add-a-use-case

    How to add a command or query to the Application layer as a vertical slice (request, handler, validator, tests) using source-generated Mediator. Use when adding a new feature, a new query, or a new write operation.

    Also in 5 projects that use this

  • LeanMeanCleanAppsSkill

    branches-and-pull-requests

    Branch naming (feature/, fix/, chore/), how labels and release notes follow from the branch, the pull request template, and how changes get merged in the template repository. Use when creating a branch, writing a commit or opening a pull request.

    Also in 5 projects that use this

  • +10 more from LeanMeanCleanApps

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. 0 are common, 14 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 20 edited versions we read keep these.

  • 14

    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:

    Write tests that each prove one behavior and, on failure, say exactly what broke.

    line 12
  2. Distinctive:

    Measure a baseline: when coverage tooling exists, and list the gaps (coverage.md).

    line 17
  3. Distinctive:

    Every test calls production code and has an assertion that can fail.

    line 30
  4. Distinctive:

    Never compute expected values with the production algorithm.

    line 32
  5. Distinctive:

    No environment-specific values (absolute paths, hostnames, ports) in tests.

    line 33
  6. Distinctive:

    Never catch and swallow exceptions to make a test pass.

    line 34
  7. Distinctive:

    Do not test the language, the framework, or a mock's configured return value.

    line 35
  8. Distinctive:

    Use the most specific assertion: exact values over truthiness, specific error types over "it failed".

    line 44
  9. Distinctive:

    Prefer per-test setup to shared mutable fixtures.

    line 51
  10. Distinctive:

    Keep integration tests separable from unit tests by directory or naming, and document their external dependencies.

    line 52
  11. Distinctive:

    Use builder or factory functions with valid defaults and keyword overrides for any complex object used by three or more tests.

    line 57
  12. Distinctive:

    Use synthetic data for unit tests.

    line 58
  13. Distinctive:

    Every public interface gets a success test and one test per documented error.

    line 62
  14. Distinctive:

    Test boundaries explicitly: zero, one, min, max, empty, null, and off-by-one.

    line 63
  15. Very specific:

    Put helpers and builders at the top of the file or in a shared module (conftest.py, testutils).

    line 78

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

Write tests that each prove one behavior and, on failure, say exactly what broke. Frameworks and commands come from whatever language standards the user has. This skill supplies the design rules.

Workflow

  1. Read the production code first. Record the exact signatures, field names, nested keys, and constructor arguments. A test that fails with unexpected keyword argument is a defect in the test.
  2. Measure a baseline when coverage tooling exists, and list the gaps (coverage.md).
  3. List equivalence classes per input: typical valid, boundary, and invalid. Plan one test per class per code path.
  4. Write each test as Arrange, Act, Assert, with exactly one action under test.
  5. Check the test can fail: picture a wrong implementation and confirm the assertion catches it.
  6. Run the suite, in isolation and in random order when the runner supports it. Re-measure coverage.
  7. Scan for anti-patterns (anti-patterns.md) and fix or delete matches.

Rules

Design

  • One logical behavior per test. Several assertions are fine only when they check facets of one outcome, such as the status and body of one response.
  • Tests are independent and deterministic. Inject clocks, seed randomness, and fake external services.
  • Every test calls production code and has an assertion that can fail.
  • Clean up everything a test creates: files, handles, globals, and environment variables.
  • Never compute expected values with the production algorithm. Derive them from requirements.
  • No environment-specific values (absolute paths, hostnames, ports) in tests.
  • Never catch and swallow exceptions to make a test pass.
  • Do not test the language, the framework, or a mock's configured return value.

Naming

  • The name states the unit, the scenario, and the expected result: withdraw_oneAboveBalance_returnsInsufficientFunds, or the runner's natural-language form. Never test1 or happyPath.
  • Suites are named after the unit under test.

Assertions

  • Use the most specific assertion: exact values over truthiness, specific error types over "it failed".
  • Give each assertion a message with what was tested, the expected value, and the actual value, so the failure is clear without opening the test.
  • Assert on observable behavior, not internals such as private state or call counts on non-critical collaborators.

Isolation

  • Unit tests replace databases, networks, file systems, and clocks with stubs, fakes, or in-memory versions.
  • Prefer per-test setup to shared mutable fixtures.
  • Keep integration tests separable from unit tests by directory or naming, and document their external dependencies.
  • For code that imports a framework that is not installed, read isolation.md.

Test data

  • Use builder or factory functions with valid defaults and keyword overrides for any complex object used by three or more tests. Tests override only the fields they care about.
  • Use synthetic data for unit tests. Use real sample files only for end-to-end parsing tests, as a complement.

Coverage

  • Every public interface gets a success test and one test per documented error.
  • Test boundaries explicitly: zero, one, min, max, empty, null, and off-by-one.
  • Negative tests assert the documented error, not just "no crash".
  • Targets: 90%+ lines for core logic, 70%+ for CLI or UI orchestration. A number alone is not a pass; shallow assertions at 95% are worse than rigorous ones at 80%.

Suites

  • Choose suites by risk and keep each runnable alone (suites.md). Performance budgets and mutation runs stay off the fast path.

Regressions

  • For each fixed bug, add a test that reproduces the original failure, named for the behavior, asserting the specific wrong result. Keep it unless the behavior is removed on purpose.

Organization

  • One test file per module, named by the language's convention (test_<module>.py, <module>.test.ts).
  • Put helpers and builders at the top of the file or in a shared module (conftest.py, testutils).

References

  • anti-patterns.md: read when reviewing tests or before declaring new tests done.
  • coverage.md: read when measuring coverage or analyzing gaps across a codebase.
  • isolation.md: read when the code under test imports a framework missing from the test environment.
  • suites.md: read when choosing which suites a project needs (unit, property, integration, end to end, contract, performance, UX, mutation) or documenting them.
  • examples.md: read for worked examples of builders, boundary sets, and regression 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.