tdd
Test-driven development with a red-green-refactor loop. Use when building features or fixing bugs test-first.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Test-driven development with a red-green-refactor loop. Use when building features or fixing bugs test-first.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | tdd |
| description | Test-driven development with a red-green-refactor loop. Use when building features or fixing bugs test-first. |
| phases | ["red","green",{"refactor":{"gate":"human"}}] |
Core principle: Tests should verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't.
Good tests are integration-style: they exercise real code paths through public APIs. They describe what the system does, not how it does it. A good test reads like a specification - "user can checkout with valid cart" tells you exactly what capability exists. These tests survive refactors because they don't care about internal structure.
Bad tests are coupled to implementation. They mock internal collaborators, test private methods, or verify through external means (like querying a database directly instead of using the interface). The warning sign: your test breaks when you refactor, but behavior hasn't changed. If you rename an internal function and tests fail, those tests were testing implementation, not behavior.
See tests.md for examples and mocking.md for mocking guidelines.
DO NOT write all tests first, then all implementation. This is "horizontal slicing" - treating RED as "write all tests" and GREEN as "write all code."
This produces crap tests:
Correct approach: Vertical slices via tracer bullets. One test → one implementation → repeat. Each test responds to what you learned from the previous cycle. Because you just wrote the code, you know exactly what behavior matters and how to verify it.
WRONG (horizontal):
RED: test1, test2, test3, test4, test5
GREEN: impl1, impl2, impl3, impl4, impl5
RIGHT (vertical):
RED→GREEN: test1→impl1
RED→GREEN: test2→impl2
RED→GREEN: test3→impl3
...
When exploring the codebase, use the project's domain glossary so that test names and interface vocabulary match the project's language, and respect ADRs in the area you're touching.
Before writing any code:
Ask: "What should the public interface look like? Which behaviors are most important to test?"
You can't test everything. Confirm with the user exactly which behaviors matter most. Focus testing effort on critical paths and complex logic, not every possible edge case.
Your very first cycle is a tracer bullet: write ONE test that confirms ONE thing about the system, then make it pass with minimal code. This proves the path works end-to-end. Every cycle after that follows the same red-green-refactor loop below, one behavior at a time.
Write exactly ONE failing test for the next behavior:
RED: Write test for next behavior → test fails
Rules:
See tests.md for what good tests look like, and mocking.md for when mocking is appropriate (mock only at system boundaries — never your own modules or internal collaborators).
Run the test suite and confirm the new test fails for the expected reason. Only then report the transition to green. Use the project's own test command (some, like zig build test, exit silently on success — a failing test must produce visible failure output).
Write the minimal implementation to make the current test pass:
GREEN: Minimal code to pass → test passes
Rules:
Run the suite; all tests pass before transitioning to refactor. Never refactor while RED.
With all tests green, improve the structure. Look for refactor candidates:
Also:
For design guidance, see deep-modules.md (small interface, deep implementation) and interface-design.md (designing for testability).
Before signing off a cycle, verify:
[ ] Test describes behavior, not implementation
[ ] Test uses public interface only
[ ] Test would survive internal refactor
[ ] Code is minimal for this test
[ ] No speculative features added
Use the VCS the project already uses — never assume one. If a VCS-specific skill is available (e.g. a jujutsu skill for jj repositories), read it before running VCS commands. Commit each completed cycle as a coherent unit, following the project's commit-message convention if one is evident from instructions or the VCS history; default to Conventional Commits otherwise (e.g. feat: ..., fix: ..., test: ...). Note that an enclosing workflow may own commits — if so, leave the working copy clean of unrelated changes and let it commit.
This workflow is one cycle. For the next behavior, transition backward to red with a reason naming the next test. The human gate on leaving refactor is the cycle's sign-off.
Use when asked to grab, take, or work on a tracked implementation issue.
Use when executing implementation plans with independent tasks in the current session
Use when you have a spec or requirements for a multi-step task, before touching code