| name | test-driven-development |
| description | Enforce TDD (Red-Green-Refactor) for features, bug fixes, and refactoring. Use when writing new functionality, fixing bugs, or when the user explicitly asks for TDD. |
| triggers | ["/tdd","test-driven","write tests first","red green refactor"] |
| allowed-tools | Read, Write, Edit, Bash, Glob, Grep, TodoWrite |
| user-invocable | true |
Test-Driven Development
Iron rule: NO production code without a failing test first.
The Cycle: RED -> GREEN -> REFACTOR
RED: Write a Failing Test
- Write one minimal test for the next behavior to implement
- Use clear naming that describes the behavior:
should reject empty email, not test1
- Test real behavior, not mocks (mocks only when unavoidable: external APIs, time, etc.)
- One assertion per test — if the name contains "and", split it
Verify RED (mandatory)
pnpm test
Confirm all 3 conditions before proceeding:
If the test passes immediately: delete it. A test that never failed proves nothing.
GREEN: Write Minimal Code
- Write the simplest code that makes the test pass
- No extra features, no "while I'm here" improvements
- Don't optimize yet — just make it green
Verify GREEN (mandatory)
pnpm test
Confirm:
REFACTOR: Clean Up
- Remove duplication
- Improve naming
- Extract helpers if needed
- Run tests again to confirm nothing broke
Then: Commit
One commit per RED-GREEN-REFACTOR cycle:
git add .
git commit -m "test: [behavior] + feat: [implementation]"
Applying TDD to Bug Fixes
- RED: Write a test that reproduces the bug (it should fail)
- Verify RED: Confirm the test fails for the right reason
- GREEN: Fix the bug with minimal code
- Verify GREEN: Bug test passes, all other tests pass
- REFACTOR: Clean up if needed
When to Skip TDD
- Text-only changes (copy, translations)
- Pure config changes (env vars, tailwind config)
- Style-only changes (CSS, spacing, colors)
- Deleting unused code
Red Flags — Restart the Cycle
Stop and go back to RED if:
- You wrote production code before writing a test
- A test passes immediately on creation
- You can't explain why the test should fail
- You're rationalizing "just this once"
If production code was written without a test: delete the code, write the test first, then reimplement from the test.
Good Test Characteristics
| Property | Meaning |
|---|
| Minimal | One behavior per test |
| Clear | Name describes the behavior, not the implementation |
| Fast | No unnecessary setup, no real network calls |
| Independent | Tests don't depend on execution order |
| Deterministic | Same result every time, no flaky tests |
Completion Checklist
Before marking the task as done: