liveBook · Manning

Snapshot comparison

As explained in Effective Behavior-Driven Development

Approval testing verifies structured results by comparing them with a previously approved result and reporting detected differences.

Approval testing, also called snapshot testing, simplifies assertions on structured results by comparing them with a previously approved result and reporting differences. A difference is not automatically an error: investigate it, then approve the new result or fix the code. section 16.4

For outputs that are difficult to compare directly, such as PDFs or complex objects, convert the result into an easier-to-read format before comparing. Comparison libraries can report differences together, rather than stopping at the first failed assertion. section 16.4 section 16.5

A weekly sales report

A test compares a generated report with an approved version. When the Margherita sales value changes from $2700 to $2701, the diff also reveals the changed daily figure and total, helping the team assess the full impact. section 16.4

Listing 16.19 The test result produced with the changed input data
Assert.IsTrue failed. 'condition' expression: 'string.IsNullOrEmpty(reportDiff)'. Reports differ
--- expected
+++ actual
@@ -1,6 +1,6 @@
 * By Pizza
   * BBQ: $2100 (35%)
-  * Margherita: $2700 (45%)
+  * Margherita: $2701 (45%)
   * Pepperoni: $1200 (20%)
 * By Day
   * 2026-03-09: $600 (10%)
@@ -9,5 +9,5 @@
   * 2026-03-12: $300 (5%)
   * 2026-03-13: $900 (15%)
   * 2026-03-14: $1800 (30%)
-  * 2026-03-15: $1200 (20%)
-* Total: $6000 (100%)
+  * 2026-03-15: $1201 (20%)
+* Total: $6001 (100%)

Inspect the report diff to see how a small input change appears across the pizza breakdown, daily figures, and total. section 16.4

How Effective Behavior-Driven Development covers it

How deep it goes
Defines comparison, review, and approval, and explains readable conversions for hard-to-compare outputs without detailing a specific library implementation.
Examples
Uses a weekly pizza-sales report to show approved output and differences in daily and total figures.
What you can do after
Evaluate a detected difference manually, then approve the new result or treat it as an error to fix.
How it connects
Connects structured results with assertions, test scenarios, and report generation.

Also explained in

Compare how 4 books explain snapshot comparison →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.