tdd-failure-recovery
Guide experienced developers through TDD failure scenarios and recovery procedures when tests behave unexpectedly
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
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
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!