Skip to content

Field Guide

Characterization tests: pin down what Gen 1 really does

Nobody can say exactly what Gen 1 does. Characterization tests find out by asking it, and then hold Gen 2 to the answers.

Slide: record what Gen 1 really does, bugs included, as characterization tests, then Gen 2 must pass the same tests. The running system is the specification.

Every rewrite plan says Gen 2 will do what Gen 1 does. Almost none can say what Gen 1 does. The documentation is years out of date, the people who wrote it have left, and the real specification is the code itself, including the parts that look like mistakes.

Characterization tests turn that code into a specification you can run. Wikipedia credits the term to Michael Feathers and gives the other name it goes by: "a characterization test (also known as Golden Master Testing) is a means to describe (characterize) the actual behavior of an existing piece of software."

Tests that describe, not judge

Ordinary tests check that code does what it should. Feathers points out the gap in that idea: it "assumes that we know what it is supposed to do." For a lot of old software, he says, "this is exactly where we are with a lot of software. We need to make changes to it but we don't know enough about what it does."

So the test is written the other way around. Feathers: "The purpose of characterization testing is to document your system's actual behavior, not check for the behavior you wish your system had."

How to write one

Feathers' recipe fits in one paragraph of his article:

  1. Write a test with a placeholder name (he names his first one "x") and a deliberately wrong expected value.
  2. Run it. The failure message tells you what the code actually returned.
  3. Paste that value into the test so it passes, and rename the test after what you learned.
  4. Repeat with the next input you are curious about.

He admits how it feels: "It's hard not to think that this is cheating in some way. It's too easy." And why it is not: "When we write characterization tests we build up our knowledge of what the code actually does. This is particularly useful when we want to refactor or rewrite."

For outputs bigger than one value, a whole report, a rendered page, an API response, the same idea scales up as a golden master. Wikipedia describes it as "comparing a complex result of the tested software-process as a whole with the result of the same process in a previous version of the software." The Approval Tests libraries are built for this: they take "a snapshot of the results, and confirming that they have not changed."

Keep the bugs

The hardest rule is not to fix anything you find while writing them. Feathers tells the story that explains why: he once fixed a bug, users complained, and "it turned out that that they depended upon the behavior I'd removed. They didn't think it was a bug, they thought it was a feature."

His conclusion is the one a rewrite needs to hear: "When a system goes into production, in a way, it becomes its own specification." A rounding rule that looks wrong may be what three downstream reports depend on. Record it. Decide later, on purpose, whether Gen 2 keeps it, and write that decision down.

Using them in a rewrite

  • Before the rewrite starts, characterize the parts of Gen 1 that Gen 2 must match. Where Gen 1 is too tangled to test from inside, test from outside: inputs at the edge, outputs at the edge.
  • Run the same tests against Gen 2. A test written against Gen 1 that passes against Gen 2 is a piece of parity you can prove instead of argue about.
  • Every failure is a decision. Either Gen 2 has a bug, or Gen 1's behavior is being changed on purpose. Both are fine. An undecided difference is not.
  • Then go live with comparison. Tests cover the inputs you thought of. A parallel run or shadow traffic compares the two generations on the inputs real users send.

Feathers names the hard part honestly: "The hardest part is breaking dependencies around a piece of code well enough to be able to exercise it in a test harness." Budget for that work. It is often the first real refactoring Gen 1 gets in years, and branch by abstraction is one way to make the seam.

When not to use it

  • Gen 2 is meant to behave differently. Test the behavior you want, and record only the parts that must stay.
  • Gen 1 already has trustworthy tests. Run those against Gen 2 first.
  • The output cannot be made repeatable. If results change on every run and cannot be pinned, compare live with a parallel run instead.
  • The feature is being dropped. Do not spend tests on behavior nobody will get.

Where it goes wrong

  • Tests that assert nothing useful. A snapshot of a whole page that changes with every timestamp fails on every run, and people stop reading the failures. Remove the moving parts before comparing.
  • Fixing bugs while characterizing. The test then describes the code you wished you had, and Gen 2 is held to a standard Gen 1 never met.
  • Characterizing everything. Cover what Gen 2 has to match, starting with what costs most if it changes: money, compliance and anything another system reads.
  • Throwing them away at cutover. They are the regression suite Gen 2 starts with.

Checklist

  • The parts of Gen 1 that Gen 2 must match are listed.
  • Each has characterization tests that pass against Gen 1, odd behavior included.
  • Large outputs are compared as golden masters, with timestamps and IDs removed first.
  • Every difference found against Gen 2 is recorded as a bug or as an intended change.
  • The tests run in Gen 2's build and stay after Gen 1 is gone.

Sources

  1. Michael Feathers - Characterization Testing (August 8, 2016) - the technique, the test named x, the purpose of documenting actual behavior, and a production system as its own specification
  2. Characterization test - Wikipedia - the term coined by Michael Feathers, the golden master name, and comparing a whole result with a previous version
  3. Approval Tests - snapshot-style approval testing of complex results, with libraries for many languages

Last updated November 29, 2026.