2026-06-09 / Extreme Programming
TDD and Unit Tests: Driving Design and Feedback
The value of TDD is not test count. It shortens design feedback through the red-green-refactor loop.
Extreme ProgrammingTDDRefactoring
TDD and Unit Tests: Driving Design and Feedback
TDD is not simply writing tests first. It compresses design feedback into a short loop: describe expected behavior, implement the minimum code, then refactor the structure.
Core Loop
stateDiagram-v2
[*] --> Red
Red: Write a failing test
Red --> Green: Implement the minimum code
Green --> Refactor: Improve design after passing
Refactor --> Red: Next behavior
Engineering Scenario
TDD is useful when rules involve boundaries, state transitions, money calculations, or permission checks. It fits domain services, value objects, and pure business rules well.
Common Mistakes
- Writing brittle tests only for coverage.
- Testing implementation details instead of behavior.
- Creating tests so large that failures are hard to diagnose.
Best Practices
- Let each test describe one behavior.
- Make Given / When / Then visible in names or structure.
- Refactor only after tests are green.
- Cover external dependencies with contracts or integration tests.