跳到正文
Skillpedia
测试95k · #1315

test-driven-development

它能做什么

这个技能引导 AI 进行测试驱动开发:先编写能展示问题的测试,然后进行小范围修复。适合希望获得改动有效性证明的开发者。

适用场景

  • ✓当你希望以先写测试的方式构建新功能的时候。
  • ✓当你需要修复 bug,并先用一个失败的测试来证明修复的时候。
  • ✓当你要改变行为,并希望避免破坏现有测试的时候。

技能链接

https://github.com/odysseus-dev/odysseus/blob/dev/resources/skills/general/test-driven-development/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请修复搜索结果为空时页面崩溃的 bug。先写一个失败的测试,再进行修复。”

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

工作原理

AI 阅读现有代码和测试,编写能展示预期行为的最小测试,并确认它失败。然后它做出能让测试通过的最小改动,并审阅差异。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

When to Use

Use when implementing a feature, fixing a bug, or changing behavior where a regression test can define the expected result. Prefer this workflow for parser, routing, agent-loop, and UI behavior changes.

Procedure

  1. Inspect the relevant code, existing tests, and local conventions before editing.
  2. Write the smallest regression test that demonstrates the requested behavior or reproduces the bug.
  3. Run that test and confirm it fails for the expected reason, not because the test setup is broken.
  4. Make the smallest production change that makes the test pass.
  5. Run the focused test again, then run the surrounding module suite.
  6. Review the diff for unrelated changes, brittle assertions, hidden state, and missing error paths.
  7. Report the tests run and any remaining coverage or environment limits.

Pitfalls

  • Do not write a test that only mirrors the implementation; assert the user-visible contract.
  • Do not weaken an assertion just to make a failing test pass.
  • Do not skip the focused failing-test step when the behavior is observable in a local test.
  • Keep network, filesystem, and model calls deterministic with fakes or fixtures unless the integration itself is under test.

Verification

  • The new regression test fails before the fix and passes after it.
  • The relevant focused suite passes.
  • The broader suite passes or its failure is explained with evidence.
  • The final diff contains the test and the production change needed for the same behavior.
常见问题

为什么测试必须先失败?

该技能说明,失败的测试可以证明该测试确实检查了这一行为,而不是偶然通过。

它会为了让测试通过而削弱测试吗?

不会。该技能说明,不要为了让失败的测试通过而减弱断言。

测试中的网络调用如何处理?

该技能会用伪造对象或测试夹具(fixtures)保持它们的可预测性,除非被测的正是连接本身。

详情

作者的原始描述

Build or fix software with a focused red-green-refactor loop

repo: odysseus-dev/odysseus

热度

GitHub 星标
95k
排名
#1315
许可证
AGPL-3.0
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能