liveBook · Manning

Test isolation

As explained in Effective Behavior-Driven Development

The principle that each scenario should run independently, without interference from other scenarios or shared state.

A scenario that passes only after another scenario has run is not reliable. Test isolation means each scenario’s outcome stands on its own, whether it runs alone, in a different order, or alongside other scenarios. section 12.4.3

Isolation requires more than keeping step data separate: the whole execution context must be unaffected by previous scenarios. For parallel runs, that includes the state of external services and resources the behavior depends on. section 12.4.3

Isolation does not prevent steps within one scenario from sharing information. A transient scenario context can hold an order number for later steps, then disappear when that execution finishes; retries get their own context. section 13.1

Listing 13.2 Scenario that uses the scenario context for order number
*** Features/Ordering.feature ***
Scenario: The customer is notified about an order cancellation
  Given the customer "Rebecca" is authenticated
  And the customer "Rebecca" has placed the order #12342 #A
  When the customer "Rebecca" cancels the placed order   #B
  Then the customer "Rebecca" should receive a notification about 
    ➥ the cancellation

This order-cancellation scenario uses the placed order from an earlier step without repeating its number. The shared context is within the scenario, not between separate executions. section 13.1

How Effective Behavior-Driven Development covers it

How deep it goes
Defines isolation as outcome independence and extends it to prior runs, execution order, parallelism, and dependent external state.
Examples
Uses an order-cancellation scenario that remembers a placed order number for later steps within that execution.
What you can do after
Build scenario automation that runs scenarios alone, in any order, or in parallel without shared state changing outcomes.
How it connects
Links isolation to scenario execution context, parallel execution, and external services and resources.

Also explained in

Compare how 6 books explain test isolation →

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.