test-design
Skill3 starsChanged 2 months agoMITView on GitHub
Use when writing, reviewing, or modifying unit/integration tests, adding test cases, assertions, or mocks, or deciding whether a piece of code is worth testing — especially when tempted to add tests for coverage, over-mock dependencies, or write formalistic tests that just restate the implementation.
11 other projects use a version of this.
Adopted by
Most recently taken up by
- mrpupkeen/test-designtheir own version, first seen Oct 6, 2026
- nahid-sparktales/agent-dispatchertheir own version, first seen Sep 21, 2026
- Hakkadaikon/hymmetheir own version, first seen Sep 9, 2026
- adamentwistle/fable-skillstheir own version, first seen Sep 3, 2026
- fang2hou/skillstheir own version, first seen Aug 18, 2026
- tlzmw001/aitest-kittheir own version, first seen Aug 13, 2026
Other versions11 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 11
- adamentwistle/fable-skills★ 98same name
- nahid-sparktales/agent-dispatcher★ 59same name
- shabaraba/vibing.nvim★ 14same name
- tlzmw001/aitest-kit★ 13same name
- yasunori0418/skills★ 8same name
- adolfoaranaes12/BMAD-ENHANCED★ 2same name
- fang2hou/skills★ 2same name
- mattstruble/skills★ 2same name
- mrpupkeen/test-design★ 1same name
- Hakkadaikon/hymme★ 0same name
1 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- commit-and-pushSkill
- debugSkill
- exploreSkill
- grillSkill
- issueSkill
- reviewSkill
- solidSkill
- tddSkill
- using-creedSkill
- write-planSkill
- write-specSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 2 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 35
After writing each test, mentally (or actually) break the logic it guards and confirm it goes red.
- Very specific: line 61
Write "when …, it should …" from the contract only.
- Distinctive: line 62
If a case was "written while reading the source", delete and rewrite it — it protects the implementation, not the contract.
- Very specific: line 97
Only replace slow/flaky/side-effecting/expensive external collaborators.
- Very specific: line 117
Test name = role + scenario + expectation (forbid case 1 / should work).
- Very specific: line 145
Test names like test1 / should work / case 2
“Common” is measured: kept by at least 6 in 10 of the 8 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.
Files
Test Design
Output language: answer and write artifacts in the user's own language (match their messages, not the repo's history).
Overview
Answers "what input should a test feed, what should it assert, and what should it mock". Does NOT cover the red-green-refactor rhythm (that is TDD).
Core principle: tests protect a behavioral contract that users/callers can observe — not implementation details, and never a coverage number. A good test is a falsifiable spec of the contract; a bad test restates the code in another syntax.
REQUIRED COMPANION: for the write-test-first rhythm, see tdd. For module boundaries when mocks multiply, see solid. This skill only governs the design quality of cases and assertions.
When to Use
- Adding or modifying unit/integration tests for a piece of code
- Reviewing someone's tests to judge whether they are effective or formalistic
- Deciding "is this code worth testing?" or "unit vs integration?"
- About to write a fake test under coverage pressure, deadline crunch, or sunk cost
When NOT to use: just running tests / reading failures → test-runner. Just following the test-first rhythm → tdd.
The Iron Law (non-negotiable)
Break one line of production code and the test protecting it MUST turn red.
If it can't, the test is formalism — delete it and rewrite.After writing each test, mentally (or actually) break the logic it guards and confirm it goes red. Violating the letter of the rule is violating the spirit — "my coverage is fine" and "I follow the spirit" do not count.
Workflow (when invoked)
Announce "Using test-design to …", then create one todo per step:
- Decide if it's worth testing (§1): complexity in own logic → unit test; in dependency wiring → integration test. Not worth it → don't write.
- Write a behavior list (§2): from the contract only — "when …, it should …", including things with no dedicated branch (e.g. "don't delete my legit content"). Each case carries its goal / conditions / parameters in reader-facing words (see §2).
- Pick representative points (§3): equivalence classes / boundaries / decision table / state transitions / dirty input — one representative each, no homogeneous duplicates.
- Write assertions (§4): assert return value / observable state / side-effect boundary only; narrow and hard; hand-write
expected. - Decide mocks (§5): mock only the outside world; count ≤ 2-3; prefer Fake/Recording.
- Mutation check (Iron Law): break production code, confirm each test goes red.
- Scan the rationalization table + red flags; if any hit, stop and rethink.
§1 Is it worth testing (ROI, not coverage)
Criterion: is the complexity in the code's own logic, or in the interaction between dependencies?
- Own logic (algorithms, pure computation, domain models/state machines, branch-heavy policy/validation/degradation) → unit test, highest ROI.
- Dependency wiring (CRUD,
A.get() → convert() → B.save()glue) → integration test. The risk of such code lives exactly where mocks replace it (dependency returns null, times out, throws, transaction not committed); a unit test only proves "it runs when everything is fine" = worthless.
Don't unit-test glue; don't integration-test algorithms.
§2 Find cases from a behavior list
Write "when …, it should …" from the contract only. Never count ifs in the source. The list MUST include items with no dedicated branch that users care about most.
If a case was "written while reading the source", delete and rewrite it — it protects the implementation, not the contract.
Each case must be legible to someone who is not the author. State three things in plain user/product words — before any code:
- Goal — what this case proves, in one sentence a non-author understands (the user-visible outcome, not the mechanism).
- Conditions — the state the case sets up (who / which data / what happened just before).
- Parameters — the concrete inputs and the expected observable result (values, and why that value is the interesting one — boundary, extreme, real case).
A case whose Goal is only readable by re-reading the source has failed this bar. Example:
Case: re-import with the same file twice
- Goal: a re-run must not double-count rows (the bug users reported as "my totals doubled")
- Conditions: the file was already imported once; no other change
- Parameters: same file; expect the row count unchanged, and an idempotency marker set§3 Five techniques to pick representative points
- Equivalence partitioning: one representative per behavior group (a second in the same group = duplicate).
- Boundary values: for every threshold test
boundary-1 / boundary / boundary+1(>=4must test "exactly 3" and "exactly 4" — that's the only way to catch>vs>=). - Decision table: enumerate combinations when output depends on multiple conditions; must include "several hit at once"; use pairwise when conditions are many.
- State transition: legal path + illegal transition (use after close) + idempotency (close×2) + repetition.
- Dirty/malicious input: empty, null, oversized, huge JSON, broken structure (missing closing tag, nesting), wrong type.
§4 Assertions (positive recipe)
Assert only these three observable targets: ① return value / thrown error (type + message + code) ② observable state change ③ side-effect boundary (whether a request was sent, where to, argument shape).
- Narrow and hard: several precise small assertions > one big
toEqual(whole object). - Hand-written
expected:expected = input.replace(sameRegex)asserts "the regex equals itself" — always green. - Don't touch implementation details: private call counts / internal branches, unless "count/order" is itself the contract (retries exactly 3 times, must not double-charge).
§5 Mock rules
Only replace slow/flaky/side-effecting/expensive external collaborators. Not for bypassing hard-to-test design.
| Do Mock | Never Mock |
| Network/HTTP/3rd-party SDK/LLM, DB/FS/MQ, clock, RNG | The unit under test, pure functions, value objects, schemas, simple in-module collaborators |
Fidelity order: Fake (in-memory) > Recording/contract replay > Spy > Mock framework. Assert only contract shape:
// Good: assert the outward contract
expect(fetchMock).toHaveBeenCalledWith(
expect.objectContaining({ method: "POST", url: expect.stringContaining("/nodes") }),
)
// Bad: lock implementation detail, red on any refactor
expect(buildPayload).toHaveBeenCalledTimes(1)§6 User perspective
Assert from the real consumer's view: end user sees results; upstream API/agent sees fields and error codes; ops sees whether logs/state can localize a problem.
Test name = role + scenario + expectation (forbid case 1 / should work); enter through the public entry point, don't drill into private functions.
§7 Shape selection
Logic-dense → pyramid (many unit tests at the base); business/CRUD → diamond (many integration tests in the middle, unit tests only for utils and core algorithms). Integration tests catch what unit tests never can: transaction commit, dropped JSON fields, param validation, real dependency failures.
Rationalization Table (how you lie to yourself before writing formalism)
| Excuse | Reality |
| "Just add a test to cover this branch" | Coverage isn't protection. Ask "what breaks for the user?"; no risk → don't test. |
"Computing expected with a function is more accurate" | That tests "the impl equals itself" — always green. expected must be a hand-written literal. |
| "Mock a bit more for cleaner isolation" | Mocking a pile = split the code or go integration; you replaced the most bug-prone spot with a fake. |
| "Might as well test this glue/CRUD too" | Its risk is entirely in the mocked-out deps; use an integration test. |
| "Testing one boundary is enough" | Off-by-one is caught only at the boundary. |
| "Testing these few cases is more thorough" | Multiple cases in one equivalence class are homogeneous duplicates = formalism. |
| "Shipping soon, verifying the call is enough" | verify(called once) protects nothing. Short on time → write less, not fake. |
| "Snapshotting the whole object is easiest" | Any unrelated field change breaks it brittly, and hides which contract failed. |
| "This test is hard to write, mock around it" | Hard to test = hard to use — a design signal; fix the code. |
| "Looks professional / 80% is required" | 100 impl-copying tests protect nothing. Quality, not quantity. |
Red Flags — stop immediately
- Adding a test just to light up a line/branch
expectedcomputed with production logic instead of hand-written- A "unit test" mocking 3+ dependencies
- Assertions are all
verify(...)/toHaveBeenCalled, none on return value/state - Test names like
test1/should work/case 2 - Testing getters/setters/DTO conversion/pure glue
- "Breaking the code probably wouldn't turn this test red"
Any hit → stop, return to: "what user-visible bad outcome does this test prevent?" Can't answer → don't write it.
Worked Example (techniques strung together)
Under test: strip(prompt) removes evidence dumps and keeps short instructions; a paragraph with ≥4 [n] citations is dropped.
Behavior list → cases (not branch-following):
// role+scenario+expectation; narrow/hard assertions; hand-written expected
test("subagent receiving a prompt with task_result has the dump stripped but instructions kept", () => {
const out = new HeuristicDumpStripper().strip(
"Summarize in three sentences.\n<task_result>…huge dump…</task_result>\nPrefer the latest conclusion.",
)
expect(out).not.toContain("<task_result>") // dump gone
expect(out).toContain("Summarize in three sentences") // leading instruction kept
expect(out).toContain("Prefer the latest conclusion") // trailing instruction kept
})
// Boundary values: threshold >=4, test "exactly 3 kept / exactly 4 dropped"
test("paragraph with exactly 3 citations is kept", () => {
expect(strip("conclusion [1][2][3] still body")).toContain("still body")
})
test("paragraph with exactly 4 citations is dropped", () => {
expect(strip("noise [1][2][3][4] should be removed")).not.toContain("should be removed")
})
// Dirty input + fallback: non-empty when everything is stripped
test("falls back to truncated original (non-empty) when stripping empties it", () => {
expect(strip("<task_result>only dump</task_result>").length).toBeGreaterThan(0)
})Mutation check: change hits.length >= 4 to >= 5; "exactly 4 dropped" MUST go red. All green → the threshold isn't tested → rewrite.
Checklist (run once per test)
- Worth testing? complex logic → unit; glue → integration
- Cases come from a behavior list, not copied from source branches
- One representative per equivalence class; boundary±1 per threshold; "several hit at once" covered
- One case each for empty/oversized/broken/malicious input
- Assert return value/observable state/side-effect only; narrow and hard;
expectedhand-written - Mock only external IO/time/RNG; the unit's logic is real; mock count ≤ 2-3
- Test name = role+scenario+expectation; enter via public API
- Mutation check passes: break production code and this test goes red
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
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.

