TDD Red Phase
TRAP 8 Defense: Tests before implementation
The Rule
Write a failing test that describes the desired behavior BEFORE writing any implementation code.
RED Phase Requirements
- Test MUST fail - If it passes immediately, you're testing the wrong thing
- Test MUST be specific - Testing exact expected behavior
- Test MUST be minimal - Only test one thing
- Test MUST compile - TypeScript clean
Test Template
describe('FeatureName', () => {
it('should [expected behavior] when [condition]', () => {
// Arrange - Set up test data
const input = createTestInput();
// Act - Execute the behavior
const result = featureUnderTest(input);
// Assert - Verify expected outcome
expect(result).toBe(expectedValue);
});
});
Before Writing Test
Ask yourself:
- What is the smallest behavior I can test?
- What exact input/output do I expect?
- Am I testing behavior, not implementation?
- Will this test fail for the right reason?
After Test Written
- Run the test with project test command
- Confirm it FAILS
- Read the failure message - it should describe missing behavior
- Proceed to GREEN phase ONLY after red confirmed
Verification
# Run test - expect FAIL
pnpm test:fast -- --run <test-file>
RED Phase Complete When
- Test is written and compiles
- Test fails when run
- Failure message describes the missing behavior
- No implementation code written yet
Failure Mode
If you skip RED:
⛔ TDD VIOLATION
Attempted: Write implementation without failing test
ACTION: Stop. Write failing test first.
Next Phase
After RED confirmed → Proceed to GREEN phase (minimal implementation to pass test)
