Characterization Tests
Michael C. Feathers, who coined the term characterization test, defines it as a test that describes (characterizes) the actual behavior of a piece of code. These tests protect the existing behavior of legacy code against unintended changes via automated testing.
In other words, they don’t check what the code is supposed to do like specification tests do, but what the code actually and currently does. Having a set of characterization tests helps developers working with legacy code because they can run these tests after modifying their code, ensuring that their modification did not cause any unintended or unwanted changes in functionality somewhere else.
- Use a piece of code in a test harness.
- Write an assertion that you know will fail.
- Run the test and let the failure tell you what the actual behavior is.
- Change the test so that it expects the behavior that the code actually produces.
- Repeat until you are reasonably sure all the...