I have a big code library that I need to refactor in order for it to fit more nicely together (one big problem is there aren't clear enough boundaries between each component). Since there will be some regression testing necessary to validate any refactoring, would it make sense to:
- Create a unit test for a particular piece of code
- Run the unit test and make sure it passes
- Refactor the code and check that the unit test still passes
This seems like a good idea to start using a TDD approach to this refactoring process, although my biggest concern is that I'm writing unit tests after the existing code (instead of writing the code after the unit tests).
Since I'm writing unit tests AFTER the code, should I first refactor, do my own regression tests, then continue using the TDD steps (write failing test, write passing code, refactor, repeat)?