tdd
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTDD Mode
TDD模式
[TDD MODE ACTIVATED]
[TDD模式已激活]
The Iron Law
铁律
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Write code before test? DELETE IT. Start over. No exceptions.
没有先编写失败的测试,绝不编写生产代码
先写代码再写测试?删除代码,重新开始。没有例外。
Red-Green-Refactor Cycle
红-绿-重构循环
1. RED: Write Failing Test
1. 红:编写失败的测试
- Write test for the NEXT piece of functionality
- Run test - MUST FAIL
- If it passes, your test is wrong
- 为下一个功能模块编写测试
- 运行测试——必须失败
- 如果测试通过,说明你的测试存在问题
2. GREEN: Minimal Implementation
2. 绿:最小化实现
- Write ONLY enough code to pass the test
- No extras. No "while I'm here."
- Run test - MUST PASS
- 只编写足够让测试通过的代码
- 不添加额外功能,不做“顺手而为”的事
- 运行测试——必须通过
3. REFACTOR: Clean Up
3. 重构:代码清理
- Improve code quality
- Run tests after EVERY change
- Must stay green
- 提升代码质量
- 每次修改后都要运行测试
- 必须保持测试通过(绿态)
4. REPEAT
4. 重复
- Next failing test
- Continue cycle
- 编写下一个失败的测试
- 继续循环
Enforcement Rules
实施规则
| If You See | Action |
|---|---|
| Code written before test | STOP. Delete code. Write test first. |
| Test passes on first run | Test is wrong. Fix it to fail first. |
| Multiple features in one cycle | STOP. One test, one feature. |
| Skipping refactor | Go back. Clean up before next feature. |
| 若发现以下情况 | 执行操作 |
|---|---|
| 先写代码再写测试 | 停止,删除代码,先编写测试 |
| 测试首次运行即通过 | 测试存在问题,修改测试使其先失败 |
| 一个循环中包含多个功能 | 停止,一个测试对应一个功能 |
| 跳过重构步骤 | 返回上一步,在开发下一个功能前完成代码清理 |
Commands
命令
Before each implementation:
bash
undefined每次实现前:
bash
undefinedRun the project's test command - should have ONE new failure
运行项目的测试命令——应该有一个新的失败测试
After implementation:
```bash
实现完成后:
```bashRun the project's test command - new test should pass, all others still pass
运行项目的测试命令——新测试应通过,其他所有测试仍保持通过状态
undefinedundefinedOutput Format
输出格式
When guiding TDD:
undefined指导TDD时:
undefinedTDD Cycle: [Feature Name]
TDD循环:[功能名称]
RED Phase
红阶段
Test: [test code]
Expected failure: [what error you expect]
Actual: [run result showing failure]
测试:[测试代码]
预期失败:[你预期的错误信息]
实际结果:[显示失败的运行结果]
GREEN Phase
绿阶段
Implementation: [minimal code]
Result: [run result showing pass]
实现代码:[最小化代码]
结果:[显示通过的运行结果]
REFACTOR Phase
重构阶段
Changes: [what was cleaned up]
Result: [tests still pass]
undefined修改内容:[清理的内容]
结果:[测试仍保持通过]
undefinedExternal Model Consultation (Preferred)
外部模型咨询(推荐)
The tdd-guide agent SHOULD consult Codex for test strategy validation.
tdd-guide agent应咨询Codex以验证测试策略。
Protocol
协议
- Form your OWN test strategy FIRST - Design tests independently
- Consult for validation - Cross-check test coverage strategy
- Critically evaluate - Never blindly adopt external suggestions
- Graceful fallback - Never block if tools unavailable
- 先制定自己的测试策略——独立设计测试用例
- 咨询以验证——交叉检查测试覆盖策略
- 批判性评估——绝不盲目采纳外部建议
- 优雅降级——若工具不可用,绝不阻塞流程
When to Consult
咨询时机
- Complex domain logic requiring comprehensive test coverage
- Edge case identification for critical paths
- Test architecture for large features
- Unfamiliar testing patterns
- 复杂领域逻辑,需要全面的测试覆盖
- 关键路径的边缘用例识别
- 大型功能的测试架构设计
- 不熟悉的测试模式
When to Skip
跳过咨询的时机
- Simple unit tests
- Well-understood testing patterns
- Time-critical TDD cycles
- Small, isolated functionality
- 简单单元测试
- 熟知的测试模式
- 时间紧迫的TDD循环
- 小型、独立的功能模块
Tool Usage
工具使用
Before first MCP tool use, call to discover deferred MCP tools.
Use with .
If ToolSearch finds no MCP tools, fall back to the Claude agent.
ToolSearch("mcp")mcp__x__ask_codexagent_role: "tdd-guide"test-engineerRemember: The discipline IS the value. Shortcuts destroy the benefit.
在首次使用MCP工具前,调用来发现延迟加载的MCP工具。
使用并设置。
若ToolSearch未找到MCP工具,回退使用 Claude agent。
ToolSearch("mcp")mcp__x__ask_codexagent_role: "tdd-guide"test-engineer记住:纪律本身就是价值所在。捷径会毁掉TDD的收益。