Characterization tests: the safety net legacy systems need

Before you change old code, capture what it does today. Characterization tests are the simplest, most underused tool in legacy modernization.

Modernization 6 min read

Legacy systems rarely come with good tests. Often they come with no tests at all, incomplete documentation and a small number of people who know how they work. Changing such a system is risky because nobody can say for certain what it is supposed to do.

Characterization tests solve this by recording what the system actually does, not what anyone thinks it should do.

What a characterization test is

A characterization test captures the current behavior of a piece of code: given these inputs, the system produces these outputs. It makes no judgment about whether the behavior is correct. It simply records it, so any change in behavior is detected.

That distinction matters. Legacy systems often contain behavior that looks like a bug but that the business depends on. Characterization tests protect that behavior until someone deliberately decides to change it.

How to write them

  1. Pick a boundary. Choose a function, service or batch job with observable inputs and outputs.
  2. Gather realistic inputs. Use production-like data, masked where necessary, plus edge cases.
  3. Run and record. Execute the code and record the outputs exactly.
  4. Turn recordings into tests. Each test asserts that the same input still produces the same output.
  5. Investigate surprises. When outputs look wrong, confirm with the business owner before deciding whether to keep or fix the behavior.

Where AI helps

Writing characterization tests by hand is tedious, which is why it is often skipped. AI changes the economics:

  • Generating inputs: suggesting edge cases and boundary values from the code’s logic
  • Drafting tests: turning recorded input and output pairs into test code
  • Explaining behavior: summarizing what a block of legacy code appears to do, so reviewers know what to check

Engineers still review every test. A characterization test suite is only valuable if it covers meaningful behavior, and deciding what is meaningful requires people who understand the business.

How they protect modernization

During modernization, the characterization tests become the contract for the new system. A new implementation is ready for traffic when it passes the same tests the old one passes, or when every difference has been explained and approved.

They also make refactoring safer before modernization even starts. Teams can clean up code, improve performance or upgrade frameworks with a clear signal when behavior changes.

Common pitfalls

  • Testing too narrowly. Tests that cover only the happy path miss the behavior that causes production incidents.
  • Using unrealistic data. Synthetic data that misses real-world quirks gives false confidence.
  • Treating recorded behavior as correct. Characterization tests describe; they do not approve. Flag suspicious behavior for review.
  • Letting them rot. Once behavior is intentionally changed, update the tests so they remain the source of truth.

You cannot safely change what you do not understand. Characterization tests are how you write that understanding down.

Tell us what you are trying to change

Share the system, the deadline and what is in the way. An engineer will reply with questions or a short proposal for next steps.

[email protected] Cary, North Carolina