tdd-failure-recovery
Guide experienced developers through TDD failure scenarios and recovery procedures when tests behave unexpectedly
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
TDD Failure Recovery
Version: {{VERSION}}
When to Use
- RED phase test passes unexpectedly (should fail)
- GREEN phase test still fails (should pass)
- REFACTOR phase breaks tests (should stay green)
- Tests behave unpredictably or inconsistently
Scenario 1: RED Phase Test Passes Unexpectedly
Possible causes:
- Feature already exists
- Test is too permissive
- Test setup incorrect
Recovery:
- Add intentional failure to verify test can fail
- Check for existing implementation
- Review test logic
- Revise test and verify it fails
- Resume TDD cycle
Scenario 2: GREEN Phase Test Still Fails
Possible causes:
- Implementation incomplete
- Implementation has bugs
- Test expectations misunderstood
Recovery:
- Read failure message carefully
- Verify implementation code
- Check test requirements
- Revise implementation
- Run full test suite
- Resume TDD cycle
Scenario 3: REFACTOR Phase Breaks Tests
Possible causes:
- Behavioral change introduced
- Breaking change in API
- Incomplete refactoring
- Test dependency on implementation
Recovery:
- IMMEDIATE ROLLBACK
- Analyze what broke
- Decide: Skip, smaller refactoring, or fix test
Critical principle:
TESTS MUST STAY GREEN
If refactoring breaks tests -> ROLLBACK
Do not proceed with broken tests
Scenario 4: Rollback Procedure
- Identify changes to undo
- Restore previous code version
- Verify file state matches pre-change
- Run full test suite
- Verify all tests GREEN
Scenario 5: Inconsistent Test Results
Possible causes:
- Test order dependency
- Timing issues
- External dependencies
- Random data in tests
Recovery:
- Run failing test alone
- Check test isolation
- Fix with proper setup/teardown
- Verify consistency
Diagnostic Flowchart
Test failed unexpectedly -> What phase?
RED: Should fail but passes -> Test invalid, revise test
GREEN: Should pass but fails -> Implementation incomplete, revise impl
REFACTOR: Should stay green but fails -> ROLLBACK immediately
Prevention Strategies
- Verify Each Phase - Never assume, always run tests
- Clear Communication - Report exact results
- Maintain Green State - Tests green except during RED phase
Common Recovery Patterns
| Pattern | Situation | Action |
|---|---|---|
| Reset | Confused state | Rollback to last green |
| Minimal Fix | Small issue | Targeted correction |
| Skip | Risk > reward | Defer to later |
| Divide and Conquer | Large change broke | Break into smaller changes |
Resources
-
resources/failure-diagnostic-flowchart.md -
resources/recovery-procedures.md -
resources/test-isolation-guide.md
End of TDD Failure Recovery Skill
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-26
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!