tdd-workflow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Follow the TDD London School (mock-first) approach:
  1. Write the failing test first -- define expected behavior with mocked dependencies
  2. Run the test -- confirm it fails for the right reason
  3. Implement minimal code -- make the test pass with the simplest solution
  4. Refactor -- clean up while keeping tests green
  5. Repeat -- add the next behavior
Before starting:
mcp__claude-flow__hooks_pre-task({ description: "TDD: FEATURE_NAME" })
After completing:
mcp__claude-flow__hooks_post-task({ taskId: "tdd-FEATURE", success: true, storeResults: true })
Principles:
  • Mock external dependencies at boundaries
  • Test behavior, not implementation
  • One assertion per test when possible
  • Descriptive names:
    should [behavior] when [condition]
遵循TDD伦敦学派(先模拟)方法:
  1. 先编写失败的测试——使用模拟依赖定义预期行为
  2. 运行测试——确认测试因正确的原因失败
  3. 实现最简代码——用最简单的解决方案让测试通过
  4. 重构——在保持测试通过的前提下清理代码
  5. 重复——添加下一个功能
开始前执行:
mcp__claude-flow__hooks_pre-task({ description: "TDD: FEATURE_NAME" })
完成后执行:
mcp__claude-flow__hooks_post-task({ taskId: "tdd-FEATURE", success: true, storeResults: true })
原则:
  • 在边界处模拟外部依赖
  • 测试行为,而非实现细节
  • 尽可能每个测试仅包含一个断言
  • 使用描述性命名:
    should [behavior] when [condition]