Characterization Tests
One of the problems with legacy code is that you can’t be sure of what it is doing. You are going to change some existing function; it is critical that the current desirable behavior is preserved. Capture the current desirable behavior in tests. Michael Feathers calls these characterization tests.
Characterization tests really help to understand the code that is being modified. If you understand the code well enough to write a test for it, you probably understand it well enough to modify it. The opposite holds true as well. If you can’t write a test for it, you probably should not modify it. Characterization tests also serve as the team’s long-term memory.
A mock object can be very helpful in characterization tests. ...