superpowers-tdd

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TDD Skill

TDD 技能

When to use this skill

适用场景

  • new features that can be unit tested
  • bug fixes (always add a regression test if practical)
  • refactors (protect behavior with tests first)
  • 可进行单元测试的新功能开发
  • 漏洞修复(若可行,务必添加回归测试)
  • 代码重构(先通过测试保障原有行为)

Rules

规则

  • Prefer red -> green -> refactor.
  • If tests are hard, still add verification: minimal repro script, integration test, or clear manual steps.
  • Keep tests focused: one behavior per test where possible.
  • Name tests by behavior, not implementation details.
  • 优先遵循红 -> 绿 -> 重构流程。
  • 若测试编写难度大,仍需添加验证机制:最简复现脚本、集成测试或清晰的手动测试步骤。
  • 保持测试聚焦:尽可能每个测试对应单一行为。
  • 测试命名基于行为,而非实现细节。

Process

流程

  1. Define the behavior change (what should be true after).
  2. Write/adjust a test to capture it (make it fail first if possible).
  3. Implement the minimal change to pass.
  4. Refactor if needed (keep passing).
  5. Run the relevant test suite + any linters.
  1. 定义行为变更(明确变更后的预期结果)。
  2. 编写/调整测试以捕获该行为(尽可能先让测试失败)。
  3. 实现最小化变更使测试通过。
  4. 如有需要进行重构(确保测试始终通过)。
  5. 运行相关测试套件及所有代码检查工具。

Output requirements

输出要求

When you change code, include:
  • what tests you added/changed
  • how to run them
  • what they prove
当你修改代码时,需包含:
  • 新增/修改的测试内容
  • 测试运行方式
  • 测试所验证的内容