TDD Workflow
Purpose
Enforce Test-Driven Development practices with the RED-GREEN-REFACTOR cycle.
Core Principles
Interface-First Design
- •Define interfaces/types before implementation
- •Consider edge cases upfront
- •Design for testability
RED Phase
- •Write a failing test for the next piece of functionality
- •Run the test to verify it fails
- •Verify it fails for the RIGHT reason (not syntax errors, import issues)
- •The test defines expected behavior
GREEN Phase
- •Write the MINIMAL code to make the test pass
- •Don't add extra functionality
- •Code quality doesn't matter yet
- •Just make it work
REFACTOR Phase
- •Improve code without changing behavior
- •Remove duplication
- •Improve naming
- •Extract methods/functions as needed
- •Tests must still pass after refactoring
Coverage Targets
- •Required: 100% for all functional code
- •Security-sensitive and critical paths must have comprehensive edge case coverage
Framework Commands
JavaScript/TypeScript (Jest)
bash
npm test # Run all tests npm test -- --coverage # With coverage npm test -- --watch # Watch mode npm test -- path/to/file # Single file
Python (pytest)
bash
pytest # Run all tests pytest --cov # With coverage pytest -v # Verbose pytest path/to/test.py # Single file
Go
bash
go test ./... # Run all tests go test -cover ./... # With coverage go test -v ./... # Verbose go test ./path/to/pkg # Single package
Test File Organization
- •Tests live alongside source or in
tests/directory - •Name pattern:
*.test.ts,*_test.py,*_test.go - •One test file per source file
- •Group related tests with describe/context blocks
Anti-Patterns to Avoid
- •Writing tests after implementation
- •Testing implementation details (not behavior)
- •Large test setups with many dependencies
- •Tests that depend on external services
- •Skipped tests without documented reason
Integration with tdd-guide Agent
This skill provides the methodology; the tdd-guide agent enforces it during code changes.