跳到正文
Skillpedia
测试81k · #1701

tdd-workflow

它能做什么

这项技能引导一个测试驱动开发的循环,采用伦敦学派的风格,即首先模拟依赖项。适用于希望在测试引领下逐步构建功能的开发者。

适用场景

  • ✓当你想从外到内、以测试优先的方式构建功能的时候。
  • ✓当你想为新行为建立清晰的红、绿、重构流程的时候。
  • ✓当你希望在任务被视为完成前检查最终测试结果的时候。

技能链接

https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-testgen/skills/tdd-workflow/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-testgen/skills/tdd-workflow/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请以测试优先的方式实现折扣计算,先为模拟的定价服务编写一个失败的测试。”

每周 5 个新技能,1 分钟读完。

工作原理

这项技能使用模拟的依赖项编写一个失败的测试,运行它以确认它因正确的原因失败,然后编写最简单的代码使其通过,最后进行重构。在报告成功之前,它会运行目标测试和回归测试,并记录实际结果。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

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__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]
常见问题

最初的失败测试是问题吗?

不是。来源说明在这种方法中,第一个红色测试是正常的。只有最终验证才决定成功与否。

什么算成功?

目标测试和回归测试套件都必须实际运行并通过。被跳过的测试不算成功。

它会记录结果吗?

会。它会把任务结果连同观察到的实际结果报告给记忆钩子。

详情

作者的原始描述

TDD London School workflow -- mock-first, outside-in test development

repo: ruvnet/ruflo

热度

GitHub 星标
81k
排名
#1701
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能