liveBook · Manning

Behavior-driven development

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

Behavior-driven development is a software development approach that specifies and verifies behavior in terms of examples meaningful to stakeholders.

A translation service can pass unit tests yet still miss what customers expected. Behavior-driven development (BDD) starts with descriptions of how a feature should behave, so the team can agree on requirements and test against them. The descriptions focus on product behavior rather than the internal calls needed to produce it. section 9.2 section 9.6

Turn a requirement into a testable scenario:

  • Given establishes the starting condition, such as a word to translate. section 3.1 section 9.2
  • When states the action: translate the word into a requested language. section 9.2
  • Then states the expected response, which becomes a validation criterion in a test. section 9.2

Check the cases before writing more tests

For a translation function, start with expected behavior for an ordinary word, capitalization, extra spaces, and an unsupported word or language. Share the list with testers or teammates to catch missing business requirements; expand it as new cases emerge. section 3.1

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"

The Gherkin feature file expresses a translation requirement as a concrete scenario: given “hello,” translating to German should return “Hallo.” Such scenarios can be converted into tests and run with a Go runner; Gherkin can also be used by other testing libraries. section 9.2

Use these scenarios alongside lower-level tests. Unit tests check a unit’s inputs, outputs, and interactions; behavior-driven scenarios check a feature against requirements that stakeholders can read. Keep the scenarios tied to useful increments of the service, including integration tests when the feature depends on external services. section 9.2 section 9.0

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

How deep it goes
Explains Given–When–Then and Gherkin through a translation scenario, but does not show Go step implementations in the supplied evidence.
Examples
Uses translation cases for capitalization, spacing, and unsupported inputs, plus a Gherkin scenario translating “hello” into German.
What it assumes
Assumes familiarity with unit tests and Arrange, Act, Assert while introducing Given–When–Then and Gherkin.
What you can do after
Apply it via Gherkin and a Go runner to check a feature against stakeholder-readable requirements.
How it connects
Connects test-driven development, unit testing, integration testing, Gherkin, and Arrange, Act, Assert.

Also explained in

Compare how 4 books explain behavior-driven development →

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.