http://qs321.pair.com?node_id=752586


in reply to how to begin with testing?

There's been a lot of great advice here, but I thought I would chime in with a different reference. I found the book Working Effectively with Legacy Code by Michael Feathers to be quite good for this particular issue.

One thing that Feathers covers that most other testing books don't is that the normal unit testing approach does not usually work well with legacy code (which he defines as code with no tests). He suggested a tactic he calls characterization tests. Instead of trying to verify correct behavior as you would with unit tests, characterization tests focus on current behavior.

Before making changes to legacy code (bug fixes, feature additions, refactorings, etc.), you would start by characterizing the current code, in the area of interest, with tests. Then, you can modify the tests and code in something approximating normal unit testing.

One of the most important points in the book is the explanation of the different tactics that you need to use for legacy code and new code that can be properly unit tested.

G. Wade

Replies are listed 'Best First'.
Re^2: how to begin with testing?
by jhourcle (Prior) on Mar 23, 2009 at 14:33 UTC

    I'm not familiar with that specific book, but when you mentioned 'Legacy Code', I was reminded of Peter J. Scott's book Perl Medic: Transforming Legacy Code. It also deal with being handed existing code, and having to maintain it. The third chapter covers tests -- it's not as complete as chromatic's book, but it does give an overview of the perl modules in CPAN (at the time) to handle testing.

      All three books complement each other. If you can read all three, I recommend it.