concept background in category software development

appears as: backgrounds, background
Writing Great Specifications: Using Specification by Example and Gherkin

This is an excerpt from Manning's book Writing Great Specifications: Using Specification by Example and Gherkin.

  • Background
  • Reusing Givens with backgrounds

    Sometimes you’ll need the same prerequisites for all the scenarios in a single feature file. Gherkin makes that easier with backgrounds.

    To better understand what a Gherkin background is, imagine you’re writing a book that features multiple narrators. Each of the narrators tells their part of the story in a separate chapter. All the chapters are happening simultaneously. To let the reader better understand the plot, you decide to add a prologue written in third-person narrative mode that explains the basic context for all the other chapters. For example, the book may be a historic action novel that pictures a chaotic aftermath of a medieval city’s burning. The prologue describes events that led to the burning. The chapters deal with the aftermath from the perspective of subsequent narrators. If Gherkin’s scenario can be compared to the book’s chapters, then a background is exactly like the prologue.

    Here’s the same specification, simplified thanks to a background.

    Listing 3.10. Givens refactored into Background
    Feature: Search and replace Background: 1 Given a text: 2 """ It was love at first sight, at last sight, at ever and ever sight. """ Scenario: Successful search When Vladimir searches for "was" Then he should be pointed to the word "was" in the text Scenario: Unsuccessful search When Vladimir searches for "best" Then he should see that there is no such word in the text Scenario: Successful search and replace When Vladimir wants to replace "was" with "is" Then the text should be: """ It is love at first sight, at last sight, at ever and ever sight. """ Scenario: Unsuccessful search and replace When Vladimir wants to replace "best" with "greatest" Then the text stay as it was: """ It was love at first sight, at last sight, at ever and ever sight. """