| name | tdd |
| description | Implements features using strict test-driven development — red-green-refactor cycle. Writes a failing test first, then minimal code to pass, then refactors. Use when building features that need high reliability. |
| argument-hint | [feature or function to implement] |
| allowed-tools | Read, Grep, Glob, Bash, Write, Edit |
Test-Driven Development
Detect Test Environment
!ls package.json pytest.ini pyproject.toml go.mod Cargo.toml *.csproj Gemfile mix.exs 2>/dev/null
!find . -type f \( -name "*.test.*" -o -name "*.spec.*" -o -name "test_*" -o -name "*_test.*" \) -not -path "*/node_modules/*" -not -path "*/.git/*" 2>/dev/null | head -5
The TDD Cycle
For the requested feature, repeat this cycle until complete:
RED — Write a Failing Test
- Write the smallest possible test that describes the next piece of behavior
- The test must import/reference the function or module (even if it doesn't exist yet)
- Run the test — it MUST fail
- Verify the failure message is meaningful (not just a compilation error)
GREEN — Make It Pass
- Write the absolute minimum code to make the test pass
- Hardcoding is acceptable at this stage — it will be cleaned up in refactor
- Don't add functionality the test doesn't require
- Run the test — it MUST pass
- Run all related tests — nothing else should break
REFACTOR — Clean Up
- Remove duplication in both production and test code
- Improve naming, extract methods, simplify logic
- Run tests after every refactoring step — they must stay green
- Stop when the code is clean
Test Progression
Start simple, add complexity gradually:
- Null/empty/zero case
- Single item / simplest valid input
- Multiple items / typical case
- Edge cases / boundary values
- Error cases / invalid input
- Async / concurrent behavior (if applicable)
Output
- Show each cycle clearly: RED (test code + failure), GREEN (impl + pass), REFACTOR
- Display test runner output at each step
- Final summary: all tests, coverage of the feature
Rules
- NEVER write implementation before a failing test
- NEVER skip the refactor step
- One behavior per cycle — don't batch multiple features
- If the test framework isn't set up, set it up first