liveBook · Manning

Clean start pattern

As explained in Effective Behavior-Driven Development

A pattern in which each scenario starts with an empty service or database and creates the data it needs.

A scenario can pass alone and fail when another scenario changes the same database. Clean Start gives each scenario an empty starting state, then makes it create the records needed for the behavior it tests. The goal is repeatable results without relying on data left behind by earlier scenarios. section 18.3 section 18.1

An order scenario

Suppose a scenario checks what happens when an order is paid. Rather than assume a suitable customer and order already exist, it creates the ones it needs. Another scenario can use different data without depending on those records. Configuration records or default lookup values may also need to be inserted; reusable insertion functions reduce that setup work over time. section 18.3

Use the pattern with its costs and limits in mind:

  • Reset before each scenario. Make the reset fast, seamless, and independent of particular record IDs. section 18.3
  • Expect more setup when writing a scenario, in exchange for independent maintenance and fewer failures caused by changes to a shared baseline. section 18.3
  • Do not treat a reset as a complete solution for parallel scenarios using one shared database: their changes can still conflict during execution. section 18.1 section 18.7

Clean Start is the simplest baseline. A seeded baseline supplies commonly needed entities instead; a snapshot baseline may suit a service whose data cannot readily be manipulated. Choose according to what the service lets scenario automation create and reset. section 18.1 section 18.7

How Effective Behavior-Driven Development covers it

How deep it goes
Explains setup responsibilities, maintenance trade-offs, and reset requirements; illustrates a database reset hook without prescribing one universal emptying technique.
Examples
Shows scenarios creating required records, reusable insertion functions, and a hook that empties database tables before execution.
What it assumes
Assumes scenario automation can reset the database and insert records; defines baseline and test data management before comparing approaches.
What you can do after
Apply it by resetting an accessible database before each scenario and creating only the records that scenario needs.
How it connects
Connects test data management and baselines to seeded data, snapshot baselines, scenario isolation, and the Insert approach.

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.