A Background is a Gherkin block that sets context shared by scenarios in a feature file. Its steps run before every scenario, so shared setup need not be repeated. section 9.6 section 8.2.1
Listing 9.7 Scenarios sharing context using Background
Background: Given a restricted customer Scenario: Restricted unauthenticated customer not offered ➥ pay-on-collection option Given they are unauthenticated When they place an order for customer-collection Then pay-on-collection should not be offered as a payment option Scenario: Restricted authenticated customer not offered pay-on-collection ➥ option Given they are authenticated When they place an order for customer-collection Then pay-on-collection should not be offered as a payment option
The restricted-customer context moves into a Background, while each scenario keeps its own authentication condition and outcome. section 9.6
Removing repetition can make a feature file less readable: readers must remember the background while following each scenario. Prefer clear, meaningful scenarios over eliminating every duplicate step. section 9.6
