tdd
Test-driven development in vertical slices: one failing test through a public interface, the minimum code to pass, repeat, with FIRST tests (fast, isolated, repeatable, self-validating, timely). Use when building features or fixing bugs test-first (red-green-refactor), writing or reviewing any test, or when tests are slow or flaky. For pacing multi-step work, use principle-take-small-verified-steps.
- License 许可
- MIT
- 最近更新
- 2026-11-10
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- tdd
- description
- Test-driven development in vertical slices: one failing test through a public interface, the minimum code to pass, repeat, with FIRST tests (fast, isolated, repeatable, self-validating, timely). Use when building features or fixing bugs test-first (red-green-refactor), writing or reviewing any test, or when tests are slow or flaky. For pacing multi-step work, use principle-take-small-verified-steps.
02 资源文件 4
- 参考文档agents/openai.yaml87 B
- 参考文档first.md3.5 KB
- 参考文档mocking.md2.2 KB
- 参考文档tests.md3.1 KB
03 SKILL.md 正文
Test-Driven Development
TDD is the red → green loop. This skill is the reference that makes that loop produce tests worth keeping: what a good test is, where tests go, the anti-patterns, and the rules of the loop. Every section applies on every cycle: consult them before and during the loop, not after.
When exploring the codebase, read GLOSSARY.md (if it exists) so test names and interface vocabulary match the project's domain language, and respect ADRs in the area you're touching.
What a good test is
Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't. A good test reads like a specification: "user can checkout with valid cart" tells you exactly what capability exists, and it survives refactors because it doesn't care about internal structure.
See tests.md for examples and mocking.md for mocking guidelines.
FIRST
Every test is FIRST. A slow or flaky test taxes every cycle that runs it, so a test that breaks a letter is a defect in the test: fix it in the same cycle, before the next test.
| Letter | The test | It holds when |
|---|---|---|
| Fast | Runs in memory: no sleep, real clock, network, database, subprocess, server, browser or model, and the smallest input that shows the behaviour | The runner's own timing shows it under 100 ms, setup included |
| Isolated | Arranges its own state, acts once, asserts one logical outcome; no other test's state or output reaches it | It passes alone and in its module's run, in any order |
| Repeatable | Fixes everything that varies: the clock, the random seed, the timezone, every remote answer | Every run, on any machine and offline, gives the same result |
| Self-validating | Decides pass or fail itself, against an expected value from outside the code | It goes red when the behaviour breaks, with no person reading its output |
| Timely | Is written just before the code that makes it pass | You saw it red first |
Some lists read the T as Thorough: at each agreed seam, cover what can really happen there (the typical case, the boundaries, illegal input, the failure path). That is thorough at the seams, never every branch; large inputs and load belong in a performance test, run apart from the loop.
A test that needs the real thing (a database, the network, a browser) is an integration or e2e test: mark it the way the repo's ### Checks says, so quick runs can leave it out, and keep the logic it covers testable below the I/O. first.md lists the usual ways a test breaks each letter, and the fix for each.
Seams: where tests go
A seam is the public boundary you test at: the interface where you observe behavior without reaching inside. Tests live at seams, never against internals.
Test only at agreed seams. Before writing any test, write down the seams under test. Take them from the spec or the ticket, or from the test policy the repo defines (### Checks in AGENTS.md or CLAUDE.md, and CODING_STANDARDS.md); ask the user only when none of these names them. You can't test everything, so agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.
When you do ask: "What's the public interface, and which seams should we test?" Give each proposed seam a one-line note on what it catches and what it misses.
Code tests never call a model, the network or a GPU: use fakes, fixtures and recorded answers. A model's behaviour is measured by evals, which are not part of this loop (principle-let-models-judge).
When the shape of that interface is itself in question (how deep the module is, where the seam belongs, what the interface should expose), call the Skill tool with "codebase-design" for the vocabulary. It is the shared source of the module, interface, depth, seam, adapter, leverage and locality terms, and it is a reference to consult, not a session to run.
Anti-patterns
- Implementation-coupled: mocks internal collaborators, tests private methods, or verifies through a side channel (querying the database instead of using the interface). The tell: the test breaks when you refactor but behavior hasn't changed.
- Tautological: the assertion recomputes the expected value the way the code does (
expect(add(a, b)).toBe(a + b), a snapshot derived by hand the same way, a constant asserted equal to itself), so it passes by construction and can never disagree with the code. Expected values must come from an independent source of truth: a known-good literal, a worked example, the spec. - Horizontal slicing: writing all tests first, then all implementation. Bulk tests verify imagined behavior: you test the shape of things rather than user-facing behavior, the tests go insensitive to real changes, and you commit to test structure before understanding the implementation. Work in vertical slices instead: one test → one implementation → repeat, each test a tracer bullet that responds to what the last cycle taught you.
Rules of the loop
- Red before green. Write the failing test first, then only enough code to pass it. Don't anticipate future tests or add speculative features.
- One slice at a time. One seam, one test, one minimal implementation per cycle.
- Run the narrowest test, and read its time. Each cycle runs the one test you are working on; when the command takes more than a few seconds, find out why before the next cycle (first.md). What runs after the loop is under Which checks to run in
principle-take-small-verified-steps. - Refactoring stays outside the loop. A preparatory refactor comes before it, in its own commit; cleanup comes after it, from the
review-codefindings.
04 同仓库更多 Skills
write-walkthrough
Guide you through running a demo yourself that shows a fix or a new feature working: a few numbered steps in the chat, each a command to copy or a click to make, with what you should see.
write-spec
Turn the current conversation into a spec and publish it to the project issue tracker: no interview, just synthesis of what you've already discussed.
write-questionnaire
Turn a decision you can't fully answer into a questionnaire for someone else to fill in.
write-pr
Writes a PR or MR from a fixed template: the tickets it closes, a summary sketch, before and after evidence that proves each acceptance criterion (screenshots for visible changes), and merge danger (one-way or two-way door, blast radius). Use when opening, writing or updating a pull request or merge request.
write-issue
Files and moves issues on the repo's tracker (GitLab, GitHub or local files): one kind (bug, feature, chore) and one stage each, a title, the kind's template, and what each later stage needs. Use when filing, relabelling, moving or closing an issue, when work should be recorded instead of done now, or to split big work into child tickets.
write-for-agents
How to write documents an agent reads: context pointers, information hierarchy, completion criteria, leading words and pruning, plus skill frontmatter and invocation mechanics. Use when creating or editing a skill, AGENTS.md, CLAUDE.md, or any doc an agent reaches through a pointer.