liveBook · Manning

Data table assertion pattern

As explained in Effective Behavior-Driven Development

A pattern for comparing tabular actual and expected outcomes while providing complete diagnostics across the comparison.

When a scenario expects several tabular results, comparing values one by one can leave failures hard to diagnose. The data table assertion pattern compares expected and actual outcomes in one operation and reports all differences. section 14.6

A table comparison can make the assertion more useful and the step definition easier to maintain:

  • Replace repeated field-by-field assertions with one comparison, supporting the atomic assertion principle. section 14.6
  • Use the resulting table diff to see all mismatches; comparison APIs may differ in row ordering and supported table shapes. section 14.6
  • Keep comparison logic separate from step-definition logic; where supported, treat null expected values as unspecified rather than comparing them. section 14.6
Listing 14.28 Test execution result on of a failing comparison
  | name        | price | original price |
  | Capricciosa | 7.99  | 8.99           |
- | Pepperoni   | 8.99  | 9.99           | 
+ | BBQ         | 8.99  | 9.99           | 

A failed comparison makes the mismatch visible: the expected Pepperoni row differs from the actual BBQ row. section 14.6

How Effective Behavior-Driven Development covers it

How deep it goes
Defines single-call comparison and full-difference diagnostics, then notes tool-specific conversions, ordering, and optional-value handling.
Examples
Uses a restaurant promotion table and a failure diff that replaces Pepperoni with BBQ.
What it assumes
Assumes expected outcomes and actual results can be represented as tables in scenario automation.
What you can do after
Apply it via Cucumber-JVM or Reqnroll comparison methods to assert tabular outcomes and inspect differences.
How it connects
Connects to atomic assertions, scenario automation, data tables, and the Data Table Accessor pattern.

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.