tdd
它能做什么
这项技能指导智能体先编写测试,再编写能通过该测试的最小代码。适合希望每项更改都由先于代码编写的测试来证明的开发者。
适用场景
- ✓当你希望新功能以测试先行的方式、一次一小步地构建的时候。
- ✓当你希望先编写一个能复现 bug 的测试,再修复它的时候。
- ✓当你希望测试来自可靠的依据,而不是来自代码本身的时候。
技能链接
https://github.com/Yeachan-Heo/oh-my-claudecode/blob/main/skills/tdd/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请参照我们定价规格中的示例,以测试先行、一次一小步的方式实现折扣规则。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会在约定的节点编写下一个测试,确认它因预期的原因失败,然后编写能使其通过的最小改动。它会重复这一循环,并把重构留到之后的审查步骤中。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
TDD
Red-green in small steps, at seams that were agreed in advance. In a launch run the seam list is C2's approved output; outside launch, agree the seams with the user before the first test exists — a seam nobody approved gets no tests.
The loop
One test → one implementation → repeat:
- Write the next test at a seam. Run it. Watch it fail for the reason you expect — a test that cannot fail is not a test.
- Implement the smallest change that turns it green.
- Repeat. Each test is a tracer bullet: a narrow but complete path through the behavior, not a layer finished in isolation.
Rules
- Expected values come from an independent source of truth — a spec line, a worked example, a documented output. Never from the implementation under test: a test that asserts what the code happens to do is a mirror, not a check.
- Substitute at the seam's declared boundary class only — in-process, locally substitutable, owned-remote port, or true-external, the class C2 records for each seam. No substitutes inside the boundary the test is exercising.
- Refactoring is not part of the loop. It belongs to the review stage; the repair worker owns it. Do not refactor mid-red-green.
- A bug fix starts with the failing test that reproduces it — reproduction before theory, the debugger's rule.
- When proposing a seam, say in one line what it catches and what it lets through — a seam choice nobody can price is a guess, not a decision.
When no seam fits
If the behavior cannot be tested at any approved seam, stop and say so: report the missing seam as a finding (it feeds architecture-survey and refit) rather than inventing a seam or testing through internals.
Output
- The seam list used, with boundary classes and each seam's catch/miss line
- Red/green evidence — the failing run and the passing run
- Any seam-absence findings
常见问题
测试会照搬代码的行为吗?
不会。预期值来自独立的依据,例如规格说明或已完成的示例,而不是来自被测代码。
测试应该写在哪里?
只写在事先约定的节点上,因此不会为无人批准的节点编写测试。
什么时候进行重构?
不在红绿循环之内进行,而是放在之后的审查阶段。
详情
作者的原始描述
Test-first at pre-agreed seams — one test, one implementation, tracer-bullet red/green; independent expected values; substitutions only at the seam's boundary class; launch Phase 4 reference.
热度
- GitHub 星标
- 41k
- 排名
- #7027
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
agent-doc-discipline
41k教你的智能体编写其他 AI 智能体能够独立遵循的说明,规则可以检验,并且每条规则都附有明确的理由。
ai-slop-cleaner
41k帮你的智能体整理 AI 写出的代码,这些代码能运行但臃肿或重复,在不改变其功能的前提下删除多余部分。
architecture-survey
41k帮你的智能体审查代码库的结构,列出越来越难修改的部分并附上证据,且自身不做任何更改。
ask-navigator
41k帮你的智能体把模糊的项目整理成一张清晰的决策问题图,然后逐个处理,直到路径变得清楚。