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
How It Works
The tdd-guide agent will:
- •Define interfaces for inputs/outputs
- •Write tests that will FAIL (because code doesn't exist yet)
- •Run tests and verify they fail for the right reason
- •Write minimal implementation to make tests pass
- •Run tests and verify they pass
- •Refactor code while keeping tests green
- •Check coverage and add more tests if below 80%
TDD Cycle
code
RED -> GREEN -> REFACTOR -> REPEAT RED: Write a failing test GREEN: Write minimal code to pass REFACTOR: Improve code, keep tests passing REPEAT: Next feature/scenario
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)
DON'T:
- •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
Integration Tests (Component-level):
- •API endpoints
- •Database operations
- •External service calls
- •React components with hooks
E2E Tests (use /e2e command):
- •Critical user flows
- •Multi-step processes
- •Full stack integration
Coverage Requirements
- •80% minimum for all code
- •100% required for:
- •Financial calculations
- •Authentication logic
- •Security-critical code
- •Core business logic
Important Notes
MANDATORY: Tests must be written BEFORE implementation. The TDD cycle is:
- •RED - Write failing test
- •GREEN - Implement to pass
- •REFACTOR - Improve code
Never skip the RED phase. Never write code before tests.
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