| name | tdd-workflow |
| description | Test-Driven Development guidance. Use during feature-dev Phase 5 (Implementation) or any code implementation. Ensures tests are written BEFORE implementation code, following Red-Green-Refactor cycle. |
TDD Workflow
CRITICAL: Tests First
During implementation, you MUST write tests before writing implementation code. This is non-negotiable.
The Red-Green-Refactor Cycle
RED: Write Failing Test
- Write a test for ONE piece of expected behavior
- Run the test - it MUST fail
- Verify it fails for the RIGHT reason (not syntax error, not import error)
- The failing test defines what you're about to implement
GREEN: Make It Pass
- Write MINIMAL code to make the test pass
- Don't over-engineer - just make it work
- Hardcoding is acceptable temporarily
- The goal is a passing test, not perfect code
REFACTOR: Clean Up
- Only refactor AFTER tests pass
- Remove duplication
- Improve naming
- Run tests after EACH refactor change
- If tests fail, undo the refactor
Rules
- NEVER write implementation before tests
- One test at a time - don't write all tests upfront
- Keep tests focused and isolated
- Each test should test ONE behavior
- Use descriptive test names that explain the expected behavior
Testing Documentation
For test patterns, utilities, and conventions, reference:
- docs/TESTING.md - Unit test patterns, MSW mocking, coverage
- docs/E2E_TESTING.md - Playwright E2E patterns
Key points from project testing standards:
- Tests go in
tests/unit/mirroringsrc/structure - Use
renderfrom@/test(not @testing-library directly) - 80% coverage required
Integration with feature-dev
During Phase 5 (Implementation):
- Before writing any component/hook/util, write its test first
- Verify test fails (RED)
- Then implement the code
- Verify test passes (GREEN)
- Refactor if needed
- Repeat for next piece of functionality
Common Mistakes to Avoid
- Writing implementation first, then tests (defeats the purpose)
- Writing all tests before any implementation (too much upfront)
- Not running tests after each change
- Writing tests that don't fail initially
- Over-engineering during the GREEN phase