TDD Workflow
Strict red-green-refactor cycle for all implementation work.
The Cycle
- •Red — Write a failing test that describes the desired behavior. Run it. Confirm it fails for the right reason.
- •Green — Write the minimum code to make the test pass. Nothing more.
- •Refactor — Clean up without changing behavior. Tests must still pass.
- •Repeat — Next behavior, next test.
Test Writing Principles
- •Test behavior, not implementation details.
- •One assertion per concept (not necessarily one per test, but each test should verify one logical thing).
- •Tests should be readable as documentation — a new developer should understand what the code does by reading the tests.
- •Name tests descriptively:
should_reject_empty_email,renders_error_state_when_api_fails.
Verification Steps
- •Run the individual test file first — faster feedback loop.
- •Run the full test suite — catch regressions.
- •Run linting/formatting — catch style issues.
- •
git diff— review what you actually changed.
When to Skip TDD
- •Configuration-only changes (env vars, build config).
- •Pure documentation.
- •Trivial renaming with existing test coverage.
Even in these cases, run the existing test suite to confirm nothing broke.
Frontend-Specific TDD
For UI components:
- •Write component/interaction tests first (render, user events, state changes).
- •Include accessibility assertions (role, aria-label, keyboard navigation).
- •Build the component to pass.
- •Visual verification is supplementary, not a replacement for tests.