‹ 首页

test-driven-development

@developersglobal · 收录于 1 周前

Red-green-refactor cycle with meaningful coverage. Tests are written before implementation. Coverage is a side effect of good tests, not the goal.

适合你,如果信奉红绿重构循环,把测试作为设计工具

/ 下载安装
test-driven-development.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add developersglobal/ai-agent-skills/test-driven-development
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- developersglobal/ai-agent-skills/test-driven-development
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify developersglobal/ai-agent-skills/test-driven-development
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
64GitHub stars
~814上下文体积 · 单文件
镜像托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · f47f948
Overview

TDD is the discipline of writing a failing test before writing implementation code. It forces you to think about the interface before the internals, produces tests that actually test behavior (not just coverage), and gives you a safety net for every refactor.

AI agents skip tests constantly. This skill makes tests non-optional.

When to Use
  • Starting any new feature or function
  • Fixing any bug (write a test that reproduces the bug first)
  • Refactoring existing code (ensure test coverage before you start)
Process
Step 1: Write a Failing Test (Red)
  1. Write a test for the behavior you want — before writing implementation.
  2. The test should describe what the code does, not how:
  3. test("returns 404 when user not found")
  4. test("calls findById with the user id")
  5. Run the test. Confirm it fails for the right reason (not a syntax error — a missing implementation).

Verify: Test runs and fails with a clear "not implemented" or "undefined" error.

Step 2: Write Minimum Code (Green)
  1. Write the minimum implementation to make the test pass.
  2. Do not write more than the test requires — resist the urge to add logic for future cases.
  3. Run the test. Confirm it passes.

Verify: All tests pass. No new tests added yet.

Step 3: Refactor (Refactor)
  1. Now clean up the implementation — no new behavior, only improved structure.
  2. Run tests after every refactoring step — do not batch refactors.
  3. If tests break during refactor: revert immediately, refactor more carefully.

Verify: Tests still pass after refactor. Code is cleaner.

Step 4: Repeat for Each Behavior
  1. Repeat steps 1–3 for each distinct behavior of the feature.
  2. Test pyramid: many unit tests, fewer integration tests, minimal end-to-end tests.
Step 5: Coverage Sanity Check
  1. Run coverage report. Flag any critical paths with 0% coverage.
  2. Do NOT chase a coverage number — write tests for behaviors that matter.

Verify: All happy paths and key edge cases have tests. Coverage report reviewed.

Common Rationalizations (and Rebuttals)

| Excuse | Rebuttal | |--------|----------| | "I'll add tests after" | After never comes. And after-the-fact tests test your implementation, not the behavior. | | "This code is too simple to test" | Simple code breaks in unexpected ways when requirements change. | | "Integration tests are enough" | Unit tests catch bugs faster, run faster, and localize failures better. | | "We don't have time for TDD" | You have time for the bug investigation that comes without TDD? |

Red Flags
  • Tests were written after the implementation
  • Tests test internal implementation details (private methods, DB queries) rather than behavior
  • "Happy path only" test coverage
  • Tests pass even when you break the implementation (mocked away the real behavior)
  • Coverage target hit by testing trivial getters/setters
Verification
  • [ ] Tests written before implementation (or alongside for bug fixes)
  • [ ] Each test describes a specific behavior
  • [ ] Red-green-refactor cycle followed
  • [ ] All tests pass
  • [ ] Key edge cases covered (empty input, null, boundary values)
  • [ ] Coverage report reviewed for critical path gaps
References
  • [debugging-methodology skill](../debugging-methodology/SKILL.md)
  • [references/testing-patterns.md](../../references/testing-patterns.md)
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。