Friday, March 25, 2005 5:26 PM szurgot

Testing Legacy Code

I'm currently in the process of adding Unit Testing to legacy system (the word legacy here meaning code without Unit Tests) The system has a very interesting design with logic in all sorts of places (ASP.NET pages, utility classes, lots of logic in Stored Procedures, etc...) This has been a most interesting experience (The word interesting here meaning worse that fingernails scraped across a chalkboard), but fortunately rather instructive. I've learned more about the system in the last few weeks that I cared too <grin>

Working with a legacy system like this has been rather interesting. Because so much of the data is in the ASP.NET pages, and so many of the stored procedures require so much setup, I'm doing most of the testing in NUnitASP. This, of course, breaks a tenent of Unit Testing, because the full battery takes several minutes, (with less than 100 tests) and an individual test can take about 10 second because of tear down and ASP.NET page compilation (I'll be glad for ASP.NET 2.0 pre-compilation) The positive side effect is that I'm optimizing each page and query, to bring the time down, which helps quite a bit...

Of course, I also have to build up the test data, so every time I change the test data script, I have to run the full battery, then retrofit my data changes to include a new # of rows or value. Which tends to throw some tests off for no particular reason... Ugh... And takes several minutes.

Of course, the more I do all of this, the cleaner the system gets, the better the code coverage gets, and the faster the system itself gets, so it's all good.

But I'll tell you what, it's all the more evidence to start writing tests as soon as possible, and to put as much logic in a place where you can excercise it quickly. It's already getting real old to run these tests, and it frustrates my boss when I put up a quick change into test and have to wait 10 minutes for all the tests to run.

Filed under:

Comments

# re: Testing Legacy Code

Saturday, March 26, 2005 5:32 AM by Roy Osherove

You might also want to look at typemock.net for dealing with legacy code that just does not lend itself easily to be tested.

# re:Testing Legacy Code

Sunday, April 10, 2005 3:00 AM by TrackBack

^_^,Pretty Good!