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. ...
Get Test Driven Development for Embedded C now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.