characterization test pattern
When you don't know what code is supposed to do, write tests that capture what it currently does — including the bugs. Now refactoring is safe: any change that breaks the characterization test is detected. Don't try to write 'correct' tests; the goal is a safety net, not a spec.
When you don't know what code is supposed to do, write tests that capture what it currently does — including the bugs. Now refactoring is safe: any change that breaks the characterization test is detected. Don't try to write 'correct' tests; the goal is a safety net, not a spec.
symptoms
- need to refactor untested code
- changes keep breaking unrelated things
causes
- no test coverage; no spec; nobody remembers
fixes
- black-box tests of current behavior
- snapshot/golden-master where output is reasonable
- refactor under their protection
you might say
- pin the behavior
- characterization test
- golden master