Refactoring is the antithesis of TDD
Thursday, April 6th, 2006I enjoy listening to the .NET ROCKS! podcasts, but I had some problems with listening to the CSLA.NET 2.0 episode today all due to what appeared to be a throwaway comment made by Richard Campbell.
Near the start of the show, a brief discussion on test driven development (TDD) took place raising a number of interesting points. One of the stand-out statements in my mind was when Richard suggested that refactoring is the “antithesis” of TDD. Stating that TDD goes against the process of refactoring as you are less likely to make changes to code when you are concerned about breaking tests. What I think was misunderstood by Richard is that this is exactly why TDD and refactoring work so well together. The tests that are generated from the process of developing tests first create an insurance policy against bugs that may be introduced when refactoring. Further, the concept behind refactoring is to perform code changes to improve code without affecting external behaviour. What this means is that if you are breaking tests while you are refactoring then there is something wrong with either your tests or your application code.
Overall, refactoring and test driven development can help you have great habits for writing robust code if you approach them in the right way.