liveBook · Manning

Given/When/Then format

As explained in Shipping Go: Develop, deliver, discuss, design, and go again

A behavioral-specification format that expresses a scenario as an initial context, an action or event, and an expected outcome.

Given/When/Then turns a business need into a testable scenario: establish the initial context, describe the action or event, and state the expected outcome. It gives developers and testers a shared starting point for deciding what to test. section 3.1 section 9.2

Use the format to expose business behavior before implementation:

  • Given a word, when it is translated into English, then return the word. section 3.1
  • Given a word with extra spaces, when translating, then return the same answer as the unspaced word. section 3.1
  • Given the word “hello,” when translating it to German, then the response should be “Hallo.” section 9.2

The format works at two levels. A team can use plain-language scenarios to build a unit-testing list, then use Gherkin feature files as requirements that a Go runner converts into validation criteria. The same feature can support backend, UI, and end-to-end tests. section 3.1 section 9.2

Listing 9.2 app.feature
Feature: Translation Service             #1
  Users should be able to submit a word to translate words within the application
 
  Scenario: Translation                  #2
    Given the word "hello"               #3
    When I translate it to "german"
    Then the response should be "Hallo"

Inspect a complete Gherkin feature for a translation service, including its Feature, Scenario, Given, When, and Then lines. section 9.2

How Shipping Go: Develop, deliver, discuss, design, and go again covers it

How deep it goes
Explains context, action, and outcome through translation examples, then connects the format to Gherkin and automated validation.
Examples
Uses translation requirements for English, capitalization, whitespace, unsupported languages, and a Gherkin hello-to-German scenario.
What it assumes
Requires enough technical knowledge to understand system behavior, while allowing project managers and customers to write readable requirements.
What you can do after
Apply it via Gherkin and a Go runner to turn readable requirements into validation criteria and automated tests.
How it connects
Connects behavior-driven development, Gherkin, Arrange-Act-Assert, unit testing, integration testing, and end-to-end testing.

Also explained in

Compare how 2 books explain Given/When/Then format →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Shipping Go: Develop, deliver, discuss, design, and go again. The section links point to the parts of the book it draws on.