跳到正文
Skillpedia
测试41k · #7027

tdd

它能做什么

这项技能指导智能体先编写测试,再编写能通过该测试的最小代码。适合希望每项更改都由先于代码编写的测试来证明的开发者。

适用场景

  • ✓当你希望新功能以测试先行的方式、一次一小步地构建的时候。
  • ✓当你希望先编写一个能复现 bug 的测试,再修复它的时候。
  • ✓当你希望测试来自可靠的依据,而不是来自代码本身的时候。

技能链接

https://github.com/Yeachan-Heo/oh-my-claudecode/blob/main/skills/tdd/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/Yeachan-Heo/oh-my-claudecode/blob/main/skills/tdd/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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:

  1. 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.
  2. Implement the smallest change that turns it green.
  3. 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.

repo: Yeachan-Heo/oh-my-claudecode

热度

GitHub 星标
41k
排名
#7027
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能