/tdd Command
This command invokes the tdd-guide agent to enforce test-driven development methodology.What This Command Does
- Scaffold Interfaces - Define types/interfaces first
- Generate Tests First - Write failing tests (RED)
- Implement Minimal Code - Write just enough to pass (GREEN)
- Refactor - Improve code while keeping tests green (REFACTOR)
- Verify Coverage - Ensure 80%+ test coverage
When to Use
Use/tdd when:
- Implementing new features
- Adding new functions/components
- Fixing bugs (write test that reproduces bug first)
- Refactoring existing code
- Building critical business logic
TDD Cycle
Command Syntax
string
required
Description of the functionality to implement with TDD
Examples
Basic Usage
Example Session
See the full example in the source documentation showing:- Step 1: Define Interface (SCAFFOLD)
- Step 2: Write Failing Test (RED)
- Step 3: Run Tests - Verify FAIL
- Step 4: Implement Minimal Code (GREEN)
- Step 5: Run Tests - Verify PASS
- Step 6: Refactor (IMPROVE)
- Step 7: Verify Tests Still Pass
- Step 8: Check Coverage (80%+ required)
TDD Best Practices
DO:- ✅ Write the test FIRST, before any implementation
- ✅ Run tests and verify they FAIL before implementing
- ✅ Write minimal code to make tests pass
- ✅ Refactor only after tests are green
- ✅ Add edge cases and error scenarios
- ✅ Aim for 80%+ coverage (100% for critical code)
- ❌ Write implementation before tests
- ❌ Skip running tests after each change
- ❌ Write too much code at once
- ❌ Ignore failing tests
- ❌ Test implementation details (test behavior)
- ❌ Mock everything (prefer integration tests)
Test Types to Include
Unit Tests (Function-level):- Happy path scenarios
- Edge cases (empty, null, max values)
- Error conditions
- Boundary values
- API endpoints
- Database operations
- External service calls
- React components with hooks
/e2e command):
- Critical user flows
- Multi-step processes
- Full stack integration
Coverage Requirements
Integration with Other Commands
- Use
/planfirst to understand what to build - Use
/tddto implement with tests - Use
/build-fixif build errors occur - Use
/code-reviewto review implementation - Use
/test-coverageto verify coverage
Related
- Agent:
~/.claude/agents/tdd-guide.md - Skill:
~/.claude/skills/tdd-workflow/ - Commands:
/plan,/test-coverage,/verify