jb-tdd
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTDD (Red-Green-Refactor)
TDD(红-绿-重构)
Use this skill whenever you need reliable, incremental implementation with test-first development.
当你需要通过测试先行的方式来实现可靠、增量式的开发时,请使用此技能。
When to use
适用场景
- Building new behavior where correctness matters
- Fixing bugs with a reproducible failing test
- Refactoring safely with behavior locked by tests
- Working in codebases where regression risk is high
- 构建对正确性有要求的新功能
- 通过可复现的失败测试来修复Bug
- 在测试锁定行为的前提下安全重构
- 在回归风险较高的代码库中工作
Workflow
工作流程
-
Red
- Write or update a test that describes the intended behavior.
- Run tests and verify the new/changed test fails for the right reason.
-
Green
- Implement the smallest possible code change to make the failing test pass.
- Run the smallest relevant test scope first, then broader tests.
-
Refactor
- Improve naming, remove duplication, simplify logic.
- Keep behavior unchanged and run tests again.
-
Repeat
- Continue in small cycles until acceptance criteria are complete.
-
红阶段
- 编写或更新测试用例,描述预期的行为。
- 运行测试,验证新增/修改的测试因正确的原因失败。
-
绿阶段
- 实现最小的代码变更,使失败的测试通过。
- 先运行最小范围的相关测试,再运行更全面的测试。
-
重构阶段
- 优化命名、消除重复代码、简化逻辑。
- 保持行为不变,再次运行测试。
-
重复循环
- 持续进行小周期迭代,直至满足验收标准。
Guardrails
注意事项
- Never skip the failing test step.
- Keep each cycle small and reviewable.
- Prefer deterministic tests over timing/network fragile tests.
- If behavior is unclear, stop and ask for clarification before coding.
- 绝不能跳过失败测试的步骤。
- 保持每个周期短小且便于评审。
- 优先选择确定性测试,而非依赖时序/网络的脆弱测试。
- 如果行为需求不明确,在编码前先停下来确认需求。
Deliverables
交付成果
- Final passing tests for all new/changed behavior
- Minimal implementation changes
- Brief summary of what each red-green-refactor cycle achieved
- 针对所有新增/修改行为的最终通过测试
- 最小化的实现变更
- 每个红-绿-重构周期成果的简要总结