tdd-workflow
它能做什么
这项技能引导一个测试驱动开发的循环,采用伦敦学派的风格,即首先模拟依赖项。适用于希望在测试引领下逐步构建功能的开发者。
适用场景
- ✓当你想从外到内、以测试优先的方式构建功能的时候。
- ✓当你想为新行为建立清晰的红、绿、重构流程的时候。
- ✓当你希望在任务被视为完成前检查最终测试结果的时候。
技能链接
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-testgen/skills/tdd-workflow/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请以测试优先的方式实现折扣计算,先为模拟的定价服务编写一个失败的测试。”
每周 5 个新技能,1 分钟读完。
工作原理
这项技能使用模拟的依赖项编写一个失败的测试,运行它以确认它因正确的原因失败,然后编写最简单的代码使其通过,最后进行重构。在报告成功之前,它会运行目标测试和回归测试,并记录实际结果。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Follow the TDD London School (mock-first) approach:
- Write the failing test first -- define expected behavior with mocked dependencies
- Run the test -- confirm it fails for the right reason
- Implement minimal code -- make the test pass with the simplest solution
- Refactor -- clean up while keeping tests green
- Repeat -- add the next behavior
Before starting: mcp__plugin_ruflo-core_ruflo__hooks_pre-task({ description: "TDD: FEATURE_NAME" })
Before reporting the outcome, run the final target tests and the regression suite after the last edit. Record the actual commands, exit codes, whether tests ran, and failing test names. The initial red test is expected during TDD; only the final validation determines success.
Call mcp__plugin_ruflo-core_ruflo__hooks_post-task with the observed result, including when the task is abandoned or validation is interrupted. Set completed, targetTestsRan, and regressionTestsRan to true only when observed; use null for missing exit codes. Skipped or unrun validation is not success. Never substitute an expected result for an observed one.
The following example maps those observations to the hook input (tool-call notation):
const success = completed && targetTestsRan && regressionTestsRan
&& targetExitCode === 0 && regressionExitCode === 0;
mcp__plugin_ruflo-core_ruflo__hooks_post-task({
taskId: "tdd-FEATURE",
success,
storeResults: true,
task: JSON.stringify({
feature: "FEATURE",
targetCommand, targetExitCode, targetTestsRan,
regressionCommand, regressionExitCode, regressionTestsRan,
failingTestNames,
failureReason: success ? null : failureReason
})
});
On failure, report success: false and the failing test names in task. If the runner failed before identifying tests, or the task was abandoned, state that reason instead of inventing test names.
Principles:
- Mock external dependencies at boundaries
- Test behavior, not implementation
- One assertion per test when possible
- Descriptive names:
should [behavior] when [condition]
常见问题
最初的失败测试是问题吗?
不是。来源说明在这种方法中,第一个红色测试是正常的。只有最终验证才决定成功与否。
什么算成功?
目标测试和回归测试套件都必须实际运行并通过。被跳过的测试不算成功。
它会记录结果吗?
会。它会把任务结果连同观察到的实际结果报告给记忆钩子。
详情
热度
- GitHub 星标
- 81k
- 排名
- #1701
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
agent-adaptive-coordinator
81k帮你的智能体在工作量变化时拆分和重新平衡一组 AI 智能体,并选择适合任务的分工方式。
agent-agent
81k教你的智能体把一个大目标拆成有顺序的行动计划,并在情况变化时重新规划。
agent-agentic-payments
81k帮你的智能体管理 AI 购物的消费授权,包括消费上限、时间窗口、商户规则和签名审批。
agent-analyze-code-quality
81k帮你的智能体检查代码质量,找出代码异味、技术债务和重构建议,且不改动文件。