一键导入
test-driven-development
Use when implementing any feature or bugfix where tests can be written first — write the test, see it fail, make it pass, refactor
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when implementing any feature or bugfix where tests can be written first — write the test, see it fail, make it pass, refactor
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when a structured PRD document is needed for the ralph loop — generates prd.json and progress.txt
Use when task scope exceeds one context window and decomposes into independent pass/fail stories with clean iteration boundaries
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work — merge, PR, or cleanup
Use when starting feature work that needs isolation from the current workspace or before executing plans that could leave the branch in a broken state
Use when a hard problem was just solved and the solution should be captured as a learning for future reference
Use when 3+ distinct occurrences suggest a skill should be updated with a new trigger, anti-pattern, or verification step
| name | test-driven-development |
| description | Use when implementing any feature or bugfix where tests can be written first — write the test, see it fail, make it pass, refactor |
| tags | ["process","testing","discipline"] |
| triggers | ["implement feature","add test","bugfix with regression test","TDD","test first","write tests"] |
| chains_to | ["verification-before-completion"] |
| priority | core |
| gate | false |
Write the test first. See it fail. Make it pass with the minimum code. Refactor. The test defines done — not your feeling about the code.
Before writing anything:
Write ONE test that captures the most important behavior:
test("should [expected behavior] when [condition]", () => {
// Arrange: set up the inputs
// Act: call the function/component
// Assert: verify the output
})
Guidelines:
Run the test. It MUST fail. If it passes, either:
A test that passes without implementation is worthless.
Write the minimum code to make the test pass. Not the "right" code. Not the "clean" code. The minimum code.
Rules:
Now that the test passes, clean up:
Run the test again after refactoring. It must still pass.
Add the next test for the next behavior. Repeat the cycle: RED → GREEN → REFACTOR
Priority order for tests:
After all tests are written and passing:
verification-before-completionBefore considering tests done:
| Anti-Pattern | Why It's Wrong |
|---|---|
| Writing implementation first, tests after | Tests become verification of your code, not specification of behavior |
| Test that never fails | It doesn't test anything |
| Testing implementation details | Tests break on refactor, providing false negatives |
| Giant test with 10 assertions | One failure, unclear which behavior broke |
| Skipping the RED step | You don't know if your test actually works |
| "I'll add tests later" | You won't. Or they'll test the wrong thing. |
| Over-mocking | Mock boundaries, not collaborators. Test real behavior. |
REQUIRED: syntaxninja-dojo:verification-before-completion (after all tests pass)