|Friday, March 18, 2005|
Increasing coverage and refactorability in legacy code
It's been over a month since I said I'd write more about Increasing coverage and refactorability for code with no unit tests, so here's my shot.
So here's the scenario: You're faced with trying to improve a large body of existing code with few to zero unit tests. The code itself is fairly monolithic, has a high degree of coupling, and maybe has an abuse of singletons, static registries or factories and too much "new" operator on large service components that make it really difficult to test a single class at a time.
To make matters worse, methods are large, the business logic isn't clear, the original requirements that drove the code (if any) aren't available. It's a tangled mess! Do you Have This (Anti-) Pattern?
So all I have is a hypothesis and some intuition, but here's the general sequence of actions that, if taken, may go some of the way toward solving the problem of increasing coverage and making it easier to refactor legacy code. The central tool in your toolbox for making this happen is none other than FIT.
What you're using FIT for in this case is for a higher-level testing tool to get some coverage for business cases that you may be able to discover, hopefully by finding and talking to a business expert. Using FIT allows you to automate the tests and get faster feedback than you would having to manually click through interfaces in your application.
I haven't yet had an opportunity to put this to practice myself, but I'd be interested to hear if anyone else has tried something similar. If you have, drop a comment!
10:01:44 PM comment  trackback