tdd

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TDD 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 SeeAction
Code written before testSTOP. Delete code. Write test first.
Test passes on first runTest is wrong. Fix it to fail first.
Multiple features in one cycleSTOP. One test, one feature.
Skipping refactorGo back. Clean up before next feature.
若发现以下情况执行操作
先写代码再写测试停止,删除代码,先编写测试
测试首次运行即通过测试存在问题,修改测试使其先失败
一个循环中包含多个功能停止,一个测试对应一个功能
跳过重构步骤返回上一步,在开发下一个功能前完成代码清理

Commands

命令

Before each implementation:
bash
undefined
每次实现前:
bash
undefined

Run the project's test command - should have ONE new failure

运行项目的测试命令——应该有一个新的失败测试


After implementation:
```bash

实现完成后:
```bash

Run the project's test command - new test should pass, all others still pass

运行项目的测试命令——新测试应通过,其他所有测试仍保持通过状态

undefined
undefined

Output Format

输出格式

When guiding TDD:
undefined
指导TDD时:
undefined

TDD 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
修改内容:[清理的内容] 结果:[测试仍保持通过]
undefined

External Model Consultation (Preferred)

外部模型咨询(推荐)

The tdd-guide agent SHOULD consult Codex for test strategy validation.
tdd-guide agent应咨询Codex以验证测试策略。

Protocol

协议

  1. Form your OWN test strategy FIRST - Design tests independently
  2. Consult for validation - Cross-check test coverage strategy
  3. Critically evaluate - Never blindly adopt external suggestions
  4. Graceful fallback - Never block if tools unavailable
  1. 先制定自己的测试策略——独立设计测试用例
  2. 咨询以验证——交叉检查测试覆盖策略
  3. 批判性评估——绝不盲目采纳外部建议
  4. 优雅降级——若工具不可用,绝不阻塞流程

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
ToolSearch("mcp")
to discover deferred MCP tools. Use
mcp__x__ask_codex
with
agent_role: "tdd-guide"
. If ToolSearch finds no MCP tools, fall back to the
test-engineer
Claude agent.
Remember: The discipline IS the value. Shortcuts destroy the benefit.
在首次使用MCP工具前,调用
ToolSearch("mcp")
来发现延迟加载的MCP工具。 使用
mcp__x__ask_codex
并设置
agent_role: "tdd-guide"
。 若ToolSearch未找到MCP工具,回退使用
test-engineer
Claude agent。
记住:纪律本身就是价值所在。捷径会毁掉TDD的收益。