with one click
tdd
// TDD with red-green-refactor loop and vertical slices. Triggers: TDD, test-first, red-green-refactor, test driving development.
// TDD with red-green-refactor loop and vertical slices. Triggers: TDD, test-first, red-green-refactor, test driving development.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | tdd |
| description | TDD with red-green-refactor loop and vertical slices. Triggers: TDD, test-first, red-green-refactor, test driving development. |
| user-invocable | true |
| effort | high |
| argument-hint | [feature or behavior to implement] |
| allowed-tools | Read, Write, Edit, Grep, Glob, Bash, Agent |
$ARGUMENTS
Build features using strict RED → GREEN → REFACTOR cycles with vertical slices.
/tdd [feature or behavior to implement]
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Write code before the test? Delete it. Start over.
No exceptions:
Implement fresh from tests. Period.
Violating the letter of this rule is violating the spirit of this rule.
Core principle: Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't.
Good tests: Integration-style, exercise real code paths through public APIs. Describe what the system does, not how. Read like specifications. Survive refactors.
Bad tests: Coupled to implementation. Mock internal collaborators, test private methods, verify through external means. Warning sign: test breaks on refactor but behavior is unchanged.
See reference/tests.md for examples, reference/mocking.md for mocking guidelines.
DO NOT write all tests first, then all implementation.
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
Tests written in bulk test imagined behavior. Vertical slices let each test respond to what you learned from the previous cycle.
Before writing any code:
Write ONE test that confirms ONE thing:
RED: Write test for first behavior → test fails
GREEN: Write minimal code to pass → test passes
This proves the path works end-to-end.
For each remaining behavior:
RED: Write next test → fails
GREEN: Minimal code to pass → passes
| Rule | Description |
|---|---|
| One at a time | One test per cycle |
| Minimal | Only enough code to pass current test |
| No anticipation | Don't code for future tests |
| Behavioral | Tests focus on observable behavior |
After all tests pass, look for refactor candidates:
Never refactor while RED. Get to GREEN first.
[ ] 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
If you catch yourself doing ANY of these, delete the code and restart with TDD:
| Excuse | Reality |
|---|---|
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
| "I'll test after" | Tests passing immediately prove nothing. |
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
| "This is different because..." | No. Apply the Iron Law. |
Before marking work complete:
Can't check all boxes? You skipped TDD. Start over.
/review to get a code review/plan for task breakdown/workflow test-coverage/debug for systematic root cause analysis