liveBook · Manning

Undo changes pattern

As explained in Effective Behavior-Driven Development

A pattern that records changes made during a scenario and reverses them to restore the baseline.

When scenarios rely on a large baseline dataset the team does not own, rebuilding it may be less efficient than tracking scenario changes and reversing them. Undo Changes restores the baseline by undoing those operations. section 18.6.1

A reset using Undo Changes follows this sequence:

  • Track inserts, updates, and deletes during scenario execution, saving the information needed to reverse them in a change journal. section 18.6.1
  • In a before-scenario reset hook, reverse the previous scenario’s journaled changes, then remove the processed entries. section 18.6.1
  • Record exactly how data changed: knowing that a record changed is not enough to restore its original values. section 18.6.1

Reversing an update

If a scenario changes a field, the journal must preserve its original value so the reset can restore it. An inserted record can be removed during reset. section 18.6.1

How Effective Behavior-Driven Development covers it

How deep it goes
Tracks inserts, updates, and deletes in a journal and reverses them before the next scenario; warns that precise history is required.
Examples
Uses deleting an inserted record and restoring a field’s original value as reversal examples.
What you can do after
Apply the pattern by journaling scenario data changes and reversing them in a before-scenario reset hook.
How it connects
Connects to snapshot baselines, Seeded Data, and Skippable Reset as approaches to scenario data setup and reset.

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.