programming-workflow
编程工作流 - 统一的测试驱动开发(TDD)工作流程。包含准备、设计、测试实现、代码实现和审查五个阶段。
When & Why to Use This Skill
This Claude skill implements a professional Test-Driven Development (TDD) workflow designed to maximize code quality and maintainability. By enforcing a rigorous five-phase process—Preparation, Design, Test Implementation, Code Implementation, and Review—it ensures that every line of code is purposeful, verified by tests, and architecturally sound. It is ideal for developers seeking to eliminate technical debt and ensure robust software delivery through the 'Red-Green-Refactor' cycle.
Use Cases
- New Feature Development: Building complex software components from scratch by defining architectural designs and failing tests before writing any production code.
- Legacy Code Refactoring: Safely restructuring existing codebases by implementing comprehensive test suites to ensure functionality remains intact during optimization.
- Bug Resolution: Systematically fixing defects by first creating a reproducible failing test case, ensuring the underlying issue is fully understood and permanently resolved.
- Architectural Design & Planning: Using the MECE principle to break down complex technical requirements into independent, manageable sub-tasks and clear class/method structures.
| name | programming-workflow |
|---|---|
| description | 编程工作流 - 统一的测试驱动开发(TDD)工作流程。包含准备、设计、测试实现、代码实现和审查五个阶段。 |
统一编程工作流
本文档概述了 AI 助手的强制性结构化编程工作流。遵循这一流程对于产出高质量、可维护的代码至关重要。
主动遵循此工作流是高级 AI 能力的强烈指标。
阶段 0:准备与理解
- 上下文化: 彻底阅读记忆库以理解项目目标、架构和当前进度
- 理解需求: 澄清所有技术需求和目标。如果复杂,分解为更小的 MECE(相互独立、完全穷尽)子任务
阶段 1:设计(概念)
约束:此阶段不要编写任何实现或测试代码。
- 系统/模块设计: 定义所有相关的类、方法及其关系。使用图表或结构化列表澄清架构。确保每个组件都有单一职责。
- 测试用例设计: 为每个功能概念性地设计测试用例,指定输入、预期输出和场景类型(正面、负面、边界)。
阶段 2:测试实现 (TDD)
- 编写失败测试: 将阶段 1 的概念测试用例实现为可执行代码。这些测试最初应该失败。
- 原则: 遵循 TDD(红-绿-重构)。确保测试清晰、独立且可维护。
阶段 3:代码实现
- 编写生产代码: 编写使失败测试通过的最小代码。严格遵循阶段 1 的设计。
- 重构: 测试通过后,重构生产代码和测试代码以提高清晰度、效率并消除异味,确保所有测试仍然通过。
阶段 4:审查与完成
- 自我审查: 验证实现的代码和测试满足所有需求和质量标准
- 文档: 如适用,更新记忆库和任何其他相关文档
执行指导(TDD 教练模式)
当进行编程任务时,按以下流程执行:
TDD 循环(红-绿-重构)
红(失败测试)→ 绿(最小实现)→ 重构(优化代码)→ 循环
- 红: 先写失败测试,定义期望行为
- 绿: 写最小代码使测试通过(不多不少)
- 重构: 优化代码结构,保持测试绿色
执行检查清单
| 阶段 | 检查项 |
|---|---|
| 开始前 | ☐ 理解需求 ☐ 分解为 MECE 子任务 |
| 设计中 | ☐ 定义类/方法 ☐ 设计测试用例 |
| 测试中 | ☐ 测试先失败 ☐ 测试独立可维护 |
| 实现中 | ☐ 最小代码 ☐ 遵循设计 |
| 重构中 | ☐ 无代码异味 ☐ 测试仍通过 |
触发条件
- 新功能开发
- Bug 修复
- 代码重构
- 任何涉及代码变更的任务
关键原则
- 测试先行: 永远先写测试,再写实现
- 小步前进: 每次只改一小点,频繁运行测试
- 持续重构: 保持代码清洁,技术债为零