Chapter 10: Tests

Characterisation test

Also called Golden master test

A test that records what old code does today, bugs included, so you can change it safely. You are writing down the behaviour before you touch it, without claiming that it is right.

This is how you let an agent refactor code nobody understands. Pin the behaviour first, then any change it makes by accident shows up. Tell it the bugs stay until you decide otherwise.

Say it to your agent

“Before refactoring src/legacy/invoice.ts, run it on these 30 real inputs, and save each output as a test in invoice.characterisation.test.ts. They must all pass unchanged after the refactor. If you find a bug, report it and don't fix it.”

The workshop

Name a word, or describe what you mean in everyday language.