Ted Husted (of Struts fame) has written a great article that talks us through using JUnit Factory to generate JUnit tests for JPetStore.
In this article, we'll use JUnit Factory to create a suite of standard JUnit tests for the Spring JPetstore business layer, so that we can refactor or extend the business logic with confidence. As we change the JPetStore code, we'll run the tests to see whether we have broken any of the code's existing behavior. As we go along, we can update the tests by hand, generate new tests, or both.
Ted's article, published in JDJ, describes how characterization tests help to bring an unfamiliar application under test, making maintenance safer and easier.
Unit tests give us the confidence to change applications, even legacy applications that we didn't write ourselves. To avoid the drudgery of writing a test case for every edge and boundary, we can let JUnit Factory generate a large set of characterization tests for us. If we need to explore an existing code base, characterization tests can act as a learning guide by documenting what the code actually does. If we need to change existing code, characterization tests act as critical "change detectors" that help us avoid unforeseen side effects.