| name | tdd |
| description | Guide a TDD (Test-Driven Development) workflow with disciplined Red-Green-Refactor cycles for the given feature or change. Use when the user is starting a new feature or behavior change and asks for TDD. |
| argument-hint | <feature or change to implement> |
Guide me through a TDD (Test-Driven Development) workflow for the given feature or change.
Workflow command for disciplined Red-Green-Refactor cycles. For batch test creation (e.g., backfilling coverage on existing code), use @test-engineer instead.
Arguments
$ARGUMENTS
- Describe the feature, function, or change to implement using TDD
- Example:
/tdd add email validation to user registration
Workflow
Follow this strict Red-Green-Refactor cycle:
Step 1: RED - Write a Failing Test
- Understand the requirement from the arguments
- Write the simplest failing test that describes the expected behavior
- Run the test to confirm it fails:
- Django:
python3 manage.py test <app.tests.TestClass> --no-input
- TypeScript:
npx vitest run <test_file> or npm test -- <test_file>
- Show the failure output to confirm the test fails for the right reason
Step 2: GREEN - Write Minimal Implementation
- Write the minimum code needed to make the failing test pass
- Do NOT add extra logic, edge cases, or optimizations yet
- Run the test again to confirm it passes
- Show the passing output
Step 3: REFACTOR - Clean Up
- Review both the test and implementation for:
- Duplication
- Naming clarity
- Unnecessary complexity
- Refactor if needed while keeping tests green
- Run all related tests to confirm nothing broke
Step 4: Next Cycle
- Ask: "What's the next behavior to test?"
- Suggest 2-3 natural next test cases (edge cases, error handling, etc.)
- Wait for user confirmation before writing the next test
- Repeat from Step 1
Rules
- Never write implementation before the test
- Never write more than one test at a time
- Never add code that isn't required by a failing test
- Each cycle should be small and focused (under 20 lines of new code)
- If the user asks to skip ahead, remind them of the TDD discipline
Output
After each cycle, show:
- Test count: total / passing / failing
- Files modified in this cycle
- Suggested next test cases