Skip to content

Characterization test

When modifying legacy code, it is often important to preserve the “actual current behavior” of the code, rather than the “desired behavior” or “documented behavior.” For example, when bugs must be kept intact to maintain compatibility. In these situations, tests written for the purpose of ensuring that “actual current behavior” is maintained are called characterization tests.

They use techniques such as unit testing, but serve a different purpose.

A characterization test is a test that characterizes the actual behavior of a piece of code. There’s no “Well, it should do this” or “I think it does that.” The tests document the actual current behavior of the system.

Steps:

  1. Use a piece of code in a test harness.
  2. Write an assertion that you know will fail.
  3. Let the failure tell you what the behavior is.
  4. Change the test so that it expects the behavior that the code produces.
  5. Repeat.

—Working effectively with legacy code

Created
Updated

Machine-translated from the Korean original.

2026 © ak | markdown | 한국어