tdd 是什么?
指导 Agent 围绕公开接口做测试驱动开发:先确认要测试的接口和行为,再一次写一个失败测试、一次实现让它通过。它特别强调测试不要依赖内部结构,也不要照着实现重算预期值。
中文说明由本站依据来源整理;英文原文保留在页面下方。
适合用在
- 新增功能或修复缺陷时,希望先写可观察行为的测试。
同名项目,请核对仓库和目录
怎么接入你的 Agent?
- 定位完整 Skill 目录
打开本项目来源,核对
SKILL.md及其引用的脚本和资料。 - 交给你正在用的 Agent
在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。
- 确认识别,再做具体任务
让 Agent 回报安装目录和识别到的名称
tdd,然后按本页使用示例提供材料。
展开并复制给 Codex 的安装指令
安装并检查 tdd
请在 Codex 的当前工作环境中安装并检查 tdd 这个 Skill。
项目身份:mattpocock/skills / tdd
来源:https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/tdd/SKILL.md
已定位的源文件:skills/engineering/tdd/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Claude Code 的安装指令
安装并检查 tdd
请在 Claude Code 的当前工作环境中安装并检查 tdd 这个 Skill。
项目身份:mattpocock/skills / tdd
来源:https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/tdd/SKILL.md
已定位的源文件:skills/engineering/tdd/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 Cursor 的安装指令
安装并检查 tdd
请在 Cursor Agent 的当前工作环境中安装并检查 tdd 这个 Skill。
项目身份:mattpocock/skills / tdd
来源:https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/tdd/SKILL.md
已定位的源文件:skills/engineering/tdd/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。展开并复制给 当前 Agent 的安装指令
安装并检查 tdd
请在 当前 Agent 的当前工作环境中安装并检查 tdd 这个 Skill。
项目身份:mattpocock/skills / tdd
来源:https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/tdd/SKILL.md
已定位的源文件:skills/engineering/tdd/SKILL.md
1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。装好以后,具体怎么用?
准备哪些材料
- 提供需求、仓库现有测试框架和运行命令;先和 Agent 确认公开测试接口(seam)及每个接口能覆盖、不能覆盖什么。
- 保留 Skill 目录中的 tests.md、mocking.md;如果接口形状尚未确定,先参考 codebase-design,不把猜出的内部方法当测试目标。
会得到什么
- 通过公开接口表达需求的行为测试,以及对应最小实现和真实 red / green 运行记录。
实际使用顺序
- 先读项目术语表和相关 ADR,列出要测试的公开接口,确认后才写测试。
- 从独立规格或手工算例取得一个确定预期值,运行测试确认它因为缺少目标行为而失败。
- 只补满足当前测试的最小实现,运行同一测试转绿,再开始下一个行为。不要先批量写完所有假想测试。
- 完成这些纵向小步后再进入 code-review 阶段安排重构;该版本把重构放在评审阶段,不混进每轮 red→green。
从一个具体任务开始
本站根据源文件编写的使用示例,未在本站实际运行。示例中的文件由你提供。
复制一个具体任务
教学示例:请用 tdd 为购物车公开函数 calculateTotal 增加满100元减10元规则。先和我确认 calculateTotal 是唯一测试接口,明确99元应为99、100元应为90。每轮只写一个行为测试并先运行失败,再实现到通过;沿用实际项目框架,不测试私有函数,不先批量生成实现。预期逐步获得临界值行为测试和实现;红绿状态取决于真实执行结果,本站未运行本例。
使用条件与边界
- 没有确认测试接口之前不写测试。
- 模拟内部协作、查询数据库绕过接口、断言实现自己算出的结果,都可能让测试失去独立判断能力。
常见问题
它会自动把所有边界情况都测完吗?
不会。源文要求先约定测试接口和覆盖范围,再根据每轮反馈推进;通过的测试只能证明这些已执行行为。
来源原文与资料状态
- 源文件
- 已保存 SKILL.md,抓取于 2026-11-16T12:36:35.145Z
- 中文使用说明
- 已针对下方源文件版本整理用途、用法和常见问题
- 安装与任务测试
- 本站未执行安装或任务测试
- 来源复核
- 本页中文用法已对照保存版本的完整 SKILL.md 阅读整理
展开 SKILL.md 原文、章节与历史收录资料
skills/engineering/tdd/SKILL.md · 抓取时间 2026-11-16T12:36:35.145Z
以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。
抓取成功不代表已完成安装或任务测试。
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
查看源文件章节 / Source sections
- 原文:Test-Driven Development
- 原文:What a good test is
- 原文:Seams: where tests go
- 原文:Anti-patterns
- 原文:Rules of the loop
原文:Test-Driven Development
TDD is the red → green loop. This skill is the reference that makes that loop produce tests worth keeping: what a good test is, where tests go, the anti-patterns, and the rules of the loop. Every section applies on every cycle: consult them before and during the loop, not after. When exploring the codebase, read `GLOSSARY.md` (if it exists) so test names and interface vocabulary match the project's domain language, and respect ADRs in the area you're touching.
原文:What a good test is
Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't. A good test reads like a specification: "user can checkout with valid cart" tells you exactly what capability exists, and it survives refactors because it doesn't care about internal structure. See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
原文:Seams: where tests go
A **seam** is the public boundary you test at: the interface where you observe behavior without reaching inside. Tests live at seams, never against internals. **Test only at pre-agreed seams.** Before writing any test, write down the seams under test and confirm them with the user. No test is written at an unconfirmed seam. You can't test everything, so agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case. Ask: "What's the public interface, and which seams should we test?" Give each proposed seam a one-line note on what it catches and what it misses. When the shape of that interface is itself in question (how deep the module is, where the seam belongs, what the interface should expose), call the Skill tool with "codebase-design" for the vocabulary. It is the shared source of the module, interface, depth, seam, adapter, leverage and locality terms, and it is a reference to consult, not a session to run.
原文:Anti-patterns
- **Implementation-coupled**: mocks internal collaborators, tests private methods, or verifies through a side channel (querying the database instead of using the interface). The tell: the test breaks when you refactor but behavior hasn't changed. - **Tautological**: the assertion recomputes the expected value the way the code does (`expect(add(a, b)).toBe(a + b)`, a snapshot derived by hand the same way, a constant asserted equal to itself), so it passes by construction and can never disagree with the code. Expected values must come from an independent source of truth: a known-good literal, a worked example, the spec. - **Horizontal slicing**: writing all tests first, then all implementation. Bulk tests verify _imagined_ behavior: you test the _shape_ of things rather than user-facing behavior, the tests go insensitive to real changes, and you commit to test structure before understanding the implementation. Work in **vertical slices** instead: one test → one implementation → repeat, each test a **tracer bullet** that responds to what the last cycle taught you.
原文:Rules of the loop
- **Red before green.** Write the failing test first, then only enough code to pass it. Don't anticipate future tests or add speculative features. - **One slice at a time.** One seam, one test, one minimal implementation per cycle. - **Refactoring is not part of the loop.** It belongs to the review stage (see the `code-review` skill), not the red → green implementation cycle.
文件 SHA256:5505d25bbaa8fc14a79e4d20163936958992a2995b7f1dd1d6197edc9ed722e0
仓库许可证记录:MIT;repository-license-recorded-scope-unverified,查看来源。
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
历史收录数据
| Skill标识 | tdd |
|---|---|
| 来源仓库 | mattpocock/skills |
| 榜单快照 | 2026-07-28 |
| 榜单口径 | Skills.sh累计安装量 |
| 快照名次 | 8 |
| 快照累计安装量 | 539203 |
历史资料说明
- 安装量用于说明当时的收录次序,不是效果、可信度或当前可用性的证明。
此页用于识别项目与来源。安装入口可在该Skill的Skills.sh页面查看;当前目录是否仍存在、附带脚本和账户依赖尚需按具体版本确认。
