Characterization Testing 101

Characterization testing is one of the most important — but insufficiently discussed — areas of software testing. It’s where you use unit testing to monitor existing code to capture the current functionality of pieces of the application. (The most common use of unit testing, by contrast, is to validate that new code works correctly.)

So, you might wonder if characterization is truly part of the “testing” part of the application life cycle, or if it’s part of maintenance. Good question, and I don’t know. In any case, characterization useful not only when doing maintenance on legacy code (when you might be trying to figure out exactly what a module does), but also during refactoring of legacy code (when you need to ensure that you didn’t break something).

On this topic, my colleague Andrew Binstock wrote a column (“Characterization: Beyond Pure Unit Testing,” SD Times, March 15) where he talked at length about the benefits of characterization during refactoring, and also where it has drawbacks.

In the column, Andrew cited the characterization features in JUnit Factory, an Eclipse plug-in and hosted test-generation service from Agitar Software. I agree that it’s a cool solution (which is currently in beta), but it’s important to note that characterization has been around for a while. Unit-test tools from Parasoft, IBM Rational and other companies support characterization as well (though they don’t necessarily use that word).

The main point that Andrew makes is an important one, and I’ll quote:

“The benefit is that if you’re refactoring legacy code, you can tell if you’ve disrupted it when any of these characterization tests fail. When you think about it, this might be about the only way of recording functionality in a faithful and actionable way. Clearly, deriving UML diagrams or flowcharts of the code is nearly pointless in this regard, because those artifacts cannot automate the process of telling you what you’ve unhinged and what its effects are.”

Want to learn more about characterization testing? Pick up a copy of “Working Effectively with Legacy Code,” by Michael Feathers, which introduces the concept and brings it to life.

Z Trek Copyright (c) Alan Zeichick
1 reply

Comments are closed.