跳到正文
Skillpedia
测试15k · #10999

tdd

它能做什么

该技能引导你从一个针对性的回归测试开始修复错误。适合希望有证据证明错误已修复、且不会再次出现的开发者。

适用场景

  • ✓当你要求测试驱动开发或回归测试的时候。
  • ✓当某个错误有一个简单、低成本的测试可以展示其错误行为的时候。
  • ✓当你希望修复能被测试证明不会再次出现的时候。

技能链接

https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/tdd/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请修复登录错误,但先写一个会失败的测试,这样我们才知道它确实被修好了。”

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

工作原理

智能体会描述错误,编写一个应当失败的小测试,运行它以确认失败,然后做出能让它通过的最小代码改动。如果低成本的测试不可行,它会改用其他检查。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

TDD Bug Fix

When fixing a bug with a clear, cheap test path, make the broken behavior executable before changing production code. The goal is a focused regression test that fails before the fix and passes after it.

Do not force a test when it would be impractical. If the available test would require broad harness setup, brittle mocks, slow end-to-end infrastructure, production-only state, vague reproduction steps, or large unrelated fixture churn, skip adding a new test and use the closest useful verification instead.

Workflow

  1. Understand the bug. Identify the intended behavior, current behavior, affected path, and smallest observable reproduction.
  2. Choose the narrowest executable check. Prefer the closest unit, component, integration, or regression test already used for that codepath. If no practical test path is obvious, do not create one from scratch just to satisfy the workflow.
  3. Write the failing test first. Add the smallest focused test that would have caught the bug. The test should encode intended behavior, not mirror the current implementation.
  4. Run the new test before fixing. Confirm it fails for the intended reason. If it passes or fails for an unrelated reason, correct the test or reproduction before editing the implementation.
  5. Fix the bug. Make the smallest production change that satisfies the intended behavior while preserving nearby contracts.
  6. Rerun the regression test. Confirm the test now passes.

If a Failing Test Is Impractical

Use the closest executable regression check instead: a targeted script, manual reproduction command, browser automation, snapshot comparison, log assertion, or focused integration check.

Prefer no new test over a bad test. A bad test is one that mostly tests mocks, encodes current implementation details, depends on timing or unrelated global state, needs expensive infrastructure for a small fix, or would be deleted immediately after proving the fix.

Guardrails

  • Do not change tests merely to match a wrong implementation.
  • Do not weaken existing assertions unless the expected behavior has genuinely changed and the reason is clear.
  • Keep the regression test focused on the bug. Avoid broad fixture churn or unrelated coverage expansion.
  • If the bug is flaky, make the test deterministic where possible and document the signal being locked down.
  • If the bug exposes a broader class of failures, first land the focused regression path, then consider additional sibling coverage.

Final Response

Report the evidence, not just the outcome:

  • Name the failing-before test or executable check and the failure it produced.
  • Name the passing-after test run and any nearby validation performed.
  • If failing-before evidence could not be demonstrated, state why and describe the closest regression check used instead.
常见问题

如果没有可行的测试怎么办?

该技能不会强制编写测试,而是使用最接近且有用的检查。

测试必须先失败吗?

是的。新测试会在修复之前运行,以确认它因正确的原因而失败。

为什么要在修复之前编写测试?

它先证明错误确实存在,之后也能证明错误何时被修复。

详情

作者的原始描述

Use only when the user explicitly asks for TDD, a failing test, or a regression test, OR when the bug has an obvious cheap local test target. Skip when the test path is unclear, expensive, integration-heavy, or not requested.

repo: cursor/plugins

热度

GitHub 星标
15k
排名
#10999
许可证
—
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能