| name | tdd |
| description | Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests. |
| 触发词 | 测试驱动开发。当用户想以测试为先的方式构建功能或修复 bug、提到「红-绿-重构」,或想要集成测试时使用。 |
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
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.
TDD 是红 → 绿的循环。本技能是让该循环产生值得保留的测试的参考指南:好测试的标准、测试的位置、反模式以及循环规则。每个部分在每个周期都适用——在循环之前和期间查阅它们,而不是之后。
When exploring the codebase, read CONTEXT.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.
探索代码库时,阅读 CONTEXT.md(如果存在),使测试名称和接口词汇与项目的领域语言匹配,并尊重你触及区域的 ADR。
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 survives refactors because it doesn't care about internal structure.
测试通过公共接口验证行为,而不是实现细节。代码可以完全改变;测试不应该。一个好的测试读起来像一份规格说明——"用户可以使用有效购物车结账"确切地告诉你存在什么能力——并且能经受重构,因为它不关心内部结构。
See tests.md for examples and mocking.md for mocking guidelines.
参见 tests.md 获取示例,mocking.md 获取模拟指南。
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 pre-agreed seams. Before writing any test, write down the seams under test and confirm them with the user. No test is written at an unconfirmed seam. You can't test everything — agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.
只在预先约定的接缝处测试。 在编写任何测试之前,写下被测的接缝并与用户确认。没有测试写在未经确认的接缝上。你无法测试所有东西——事先约定接缝,测试工作才能落在关键路径和复杂逻辑上,而不是每种边缘情况。
Ask: "What's the public interface, and which seams should we test?"
请问:"公共接口是什么,我们应该测试哪些接缝?"
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.expect(add(a, b)).toBe(a + b)、以同样方式手工推导的快照、一个断言等于自身的常量),因此它按构造通过,永远无法与代码产生分歧。期望值必须来自独立的真值来源——已知良好的字面量、经过手工计算的示例、规格说明。code-review skill), not the red → green implementation cycle.code-review 技能),而不是红 → 绿的实现周期。