TDD
Write the test before the implementation. Always.
Cycle
RED → Write a failing test that captures expected behavior
GREEN → Write the minimum code to make it pass
REFACTOR → Clean up while tests stay green
Steps
- Understand the requirement
- Write one failing test for the happy path
- Run it — confirm it fails for the right reason
- Write minimum implementation to pass
- Run it — confirm green
- Refactor if needed (tests must stay green)
- Add edge case tests after happy path works
Rules
- Never write implementation before the test exists
- Test behavior, not implementation details
- One assertion focus per test
- If you cannot write a test, clarify the requirement first
- Mock external dependencies; do not mock internal logic
- Coverage is a signal, not a target — test business value