Test-driven development with red-green-refactor loops built around vertical slices (tracer bullets), not horizontal layers. Use when asked to "use TDD", "write
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-tdd-1eaf172376e0 ,按照其中的说明把「tdd」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Invocation points:
Do not use this skill for:
/gsd start spike — no production code ships)<core_principle> TESTS VERIFY BEHAVIOR THROUGH PUBLIC INTERFACES, NOT IMPLEMENTATION DETAILS. A good test reads like a specification and survives refactors. A test that mocks internals or asserts private state fails every time you clean up the code — that is a bad test pretending to be a good one.
VERTICAL SLICES, NOT HORIZONTAL LAYERS. Writing all tests upfront ("horizontal slicing") produces tests for behavior you imagined, not behavior the code actually exhibits. One tracer bullet at a time: write one test, make it pass, learn, write the next.
NEVER REFACTOR WHILE RED. Refactoring without a passing test means you are guessing whether you broke something. Get to green first. Then clean up. Then go red again for the next slice. </core_principle>
Before writing anything:
If the user has not supplied these, ask — one round, 1–3 questions.
Pick the first behavior — usually the happy path for the most common input. Write one test that exercises it end-to-end through the public interface. Run it. It must fail (RED). If it passes, the test is not testing what you think it is — fix the test before writing any code.
Then write the minimum code to make it pass. "Minimum" means: if hard-coding return 42 makes the test pass, hard-code return 42. You will generalize on the next cycle. Run the test. It must pass (GREEN).
This proves the end-to-end path works — test harness, imports, wiring, build. Everything from Step 3 onward is incremental.
Pick the next behavior. Write one test that pins it. Run — RED. Write the minimum code that makes it pass without breaking prior tests. Run — GREEN.
Guidelines for picking the next behavior:
Guidelines for writing the test:
expect calls that describe one behavior are fine).Guidelines for writing the code:
Now that the behavior is pinned, clean up. Extract duplicated logic. Rename unclear variables. Deepen the module — move responsibilities behind the interface until the internals stop leaking into the test.
Rules:
When the behavior the task plan specified is fully under test and the code is clean:
.gsd/KNOWLEDGE.md if the behavior is non-obvious or the test surfaced a trap future agents should know about.gsd_* tools to mark the task complete — do not edit checkboxes by hand.<anti_patterns>
jest.mock("./internal-helper") tells you the wiring matches your mental model, not that the behavior is correct.fetchUser three times." Who cares? Test the observable result.</anti_patterns>
<success_criteria>
</success_criteria>