> [!abstract] > A testing pattern that replaces assertions with explicit human approval of diffs — arrange-act-print-diff instead of arrange-act-assert. ## The pattern Instead of asserting an expected value, you **print the result** and diff it against a previously **approved** version. The test name comes from the deliberate act of reviewing and approving that output. The mechanics: run the test once to produce a **received file**, review it, then approve it as the baseline. Future runs compare against that approved file — pass if identical, fail if different. Produces **three-state output** rather than the two-state pass/fail of assertion-based tests: - **No change** — confident, nothing to do - **Expected change** — approve it and move on - **Unexpected change** — something to investigate; likely a bug ## Benefits - **Complex output**: particularly suited to objects or subsystems with rich output — where writing individual assertions would be tedious. A picture's worth 1000 tests. - **Diagnosability**: failing tests show a diff with full context — what stayed the same and what changed — making root cause analysis easier - **Bulk updates**: when behavior intentionally changes, approve the new output and all related tests go green; one logical change causing many failures is often one approve-all operation ## Challenges - New tests go through a **stabilization phase** — irrelevant output must be scrubbed or filtered before tests are reliably stable - **Social pressure**: under stress, developers may approve diffs without careful review, silently accepting bugs - Cascading failures (many tests failing for one reason) can cause panic until you recognise it's a single root cause ## Tooling Use an established approval testing framework rather than building your own — the tooling to interpret results is the hard part. Good tools: - Group related failures together - Warn when approving output containing stack traces - Help distinguish multiple distinct failure causes ## Comparison with related terms See [[Approval testing vs Snapshot assertion]] for how this differs from snapshot testing and golden master testing. ## Further reading Emily Bache is one of the leading practitioners and teachers of approval testing: - [Approval Testing by Example](https://leanpub.com/approval-testing-by-example) — her book on Leanpub with worked examples - [Approval Testing](https://medium.com/97-things/approval-testing-33946cde4aa8) — concise article in the *97 Things* series - [Approval Testing Intro Learning Hour](https://sammancoaching.org/learning_hours/legacy/approval_testing_intro.html) — practical hands-on exercise via Samman Coaching - [Hands-On Approval Testing for Developers](https://www.oreilly.com/live-events/hands-on-approval-testing-for-developers/0636920065094/) — O'Reilly live training - [emilybache on GitHub](https://github.com/emilybache) — katas including Gilded Rose, Yatzy, Supermarket Receipt ## Sources [[Video - Approval Tests vs Acceptance Tests Whats the Difference]]