patterntypescriptTip
Approval testing: human-reviewable output diffs as the test assertion mechanism
Viewed 0 times
approval testingapprovaltestsreceived approveddiff testinghuman review assertion
Problem
Complex output (HTML reports, PDF pages, generated SQL, CLI tables) is too verbose to assert field-by-field. Writing assertions for every cell in a 50-column table is impractical. Snapshot testing hides the full diff in a wall of text.
Solution
Use an approval testing framework (ApprovalTests.Net, Approvals for JS, or a custom implementation). The test produces output, which is written to a
.received file. The developer compares it against a .approved file using a diff tool. Approving merges received into approved. CI fails if they differ.Why
The diff tool is optimized for human review of structured text. Approvals are explicit version-controlled decisions, not automatic snapshot updates. The approved file is the living specification of expected output.
Gotchas
- Approved files must be committed to source control alongside tests
- Output must be deterministic — use stable sort orders and fixed timestamps
- Large approval files obscure the intent; break into smaller test cases with focused approved outputs
- CI must use the same line endings as local to avoid spurious diff failures on Windows
Revisions (0)
No revisions yet.