tdd
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTDD Protocol
TDD 规范
Core Principle
核心原则
- TDD First: Test-Driven Development is the default approach.
- Goal: Prioritize behavioral correctness and regression safety over formal compliance.
- 优先采用TDD:测试驱动开发是默认方法。
- 目标:优先保证行为正确性和回归安全性,而非形式上的合规。
Workflow
工作流
- Requirement Synthesis: Briefly summarize the requirements before coding.
- Test Specification: Write tests describing the expected behavior (unit, integration, or E2E).
- Implementation: Update the logic only to the extent required to satisfy those tests.
- 需求梳理:编码前简要总结需求。
- 测试用例编写:编写描述预期行为的测试(单元测试、集成测试或E2E测试)。
- 实现:仅更新满足这些测试所需的逻辑。
Mandatory Rules
强制规则
- No Test, No Code: Every new feature or bugfix must include relevant test coverage.
- Black-Box Testing: Validate observable behavior, not internal implementation details.
- Merge Requirement: Tests are mandatory for completion unless an explicit exception is documented.
- 无测试,不编码:每个新功能或bug修复都必须包含相关测试覆盖。
- 黑盒测试:验证可观察的行为,而非内部实现细节。
- 合并要求:除非有明确记录的例外情况,否则测试是完成工作的必要条件。
Preferred Practice
推荐实践
- Red-Green-Refactor: Start with a failing test whenever practical.
- Right-Sized Testing:
- Unit Tests: For pure logic and isolated functions.
- Integration Tests: For system interactions and API boundaries.
- E2E Tests: For critical user journeys and "happy paths."
- 红-绿-重构:尽可能从失败的测试开始。
- 适配规模的测试:
- 单元测试:针对纯逻辑和独立函数。
- 集成测试:针对系统交互和API边界。
- E2E测试:针对关键用户流程和“顺畅路径”。
Explicit Exceptions (Must be justified)
明确例外情况(必须说明理由)
- Pure refactoring (where behavior remains identical).
- Exploratory spikes or R&D.
- UI/Styling iterations where unit tests offer diminishing returns.
- Complex integrations where mocking is counterproductive.
- Emergency hotfixes (requires a follow-up ticket for test debt).
- 纯重构(行为保持完全一致)。
- 探索性研究或研发工作。
- UI/样式迭代,此时单元测试的收益递减。
- 复杂集成,此时模拟(mocking)会产生反效果。
- 紧急热修复(需要后续工单来处理测试债务)。
Quality Bar
质量标准
- Readability: Tests must serve as documentation for the feature.
- Reliability: Tests must be deterministic (no flakes) and decoupled from implementation internals.
- 可读性:测试必须作为功能的文档。
- 可靠性:测试必须是确定性的(无不稳定测试),且与实现内部细节解耦。