Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing Legacy ASP.NET Webforms Applications [closed]

I've inherited a legacy web application that has no unit tests in it. I'd like to add some, but am at a loss of where to start. Should I add them to old code? Or just new code going forward? What if that code interacts with legacy code? What would you suggest?

like image 251
George Stocker Avatar asked Dec 05 '08 01:12

George Stocker


2 Answers

First, I would recommend unit testing all changes going forward, I think most everyone would agree this is a good idea for regression.

However, for existing code, this is one of those situations where you need to look at how much risk you're willing or allowed to introduce into the product. The problem is that when you start to unit test an existing code base, you're going to soon realize many opportunities for refactoring and design refinement.

Take it from me, if you're a stickler for good design, but you haven't been empowered to make drastic refactoring descisions, you're only going to end up with a broken heart when you try to write tests for the legacy parts -- and yes, if it doesn't have existing test suite its going to NEED refactoring. If you're not allowed to make high impact changes to the production application, you're going to end up implementing something we like to call the "garbage adapter pattern". Good luck!

like image 94
jonathan.cone Avatar answered Oct 13 '22 01:10

jonathan.cone


I would suggest getting a copy of Working Effectively with Legacy Code.

We went through this book in a study group. it was painful, but useful.

Topics include:

  • Understanding the mechanics of software change: adding features, fixing bugs, improving design, optimizing performance
  • Getting legacy code into a test harness
  • Writing tests that protect you against introducing new problems
  • Techniques that can be used with any language or platform-with examples in Java, C++, C, and C#
  • Accurately identifying where code changes need to be made
  • Coping with legacy systems that aren't object-oriented
  • Handling applications that don't seem to have any structure

You can see a short into to this at http://www.objectmentor.com/resources/articles/WorkingEffectivelyWithLegacyCode.pdf

like image 41
Ray Tayek Avatar answered Oct 12 '22 23:10

Ray Tayek