Design Patterns · Middle · Question 69 of 75
How do you safely refactor legacy code without tests?
- ✓Correct answer: First write characterization tests that capture current behavior, then refactor in small steps
- 2Rewrite it from scratch
- 3Refactor and test manually afterwards
Explanation
Characterization tests lock in what the code does today (even bugs). Seams let you inject test doubles.