liveBook · Manning

Godog

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

Godog is a Go library and test runner for executing Gherkin-based behavior-driven development specifications.

Godog is a Go library and test runner for executing Gherkin-based behavior-driven development specifications against an application’s main package. It turns user-facing feature definitions into integration tests that can fail before implementation is complete, creating a useful feedback loop as requirements change. section 9.2

A practical Godog workflow looks like this:

  • Write a feature file describing the expected behavior, then place it where Godog can discover it, such as cmd/features. section 9.2 section 9.3
  • Install the runner through a Makefile with go install github.com/cucumber/godog/cmd/godog@latest, then run godog run. section 9.3
  • Copy Godog’s generated step-definition snippets into main_test.go and replace pending handlers with scenario behavior. section 9.3
  • Expose application construction through a reusable API function so tests can start the same HTTP service without invoking main directly. section 9.3

Translation scenario

A feature can describe a translation service in plain language: Given the word "hello", When I translate it to "german", Then the response should be "Hallo". Step handlers capture the word and language, call /translate/hello with the language query parameter, and compare the returned translation with the expected value.

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"

Browse the complete Gherkin feature for the translation service, including its feature statement, scenario, steps, and expected response. section 9.2

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

How deep it goes
Follows installation, feature discovery, generated steps, application refactoring, scenario hooks, HTTP calls, and response assertions.
Examples
Demonstrates a translation feature, generated pending step handlers, a reusable API constructor, and an httptest-backed Resty request.
What it assumes
Assumes a Go application with an HTTP API and teaches feature definitions, step wiring, application startup, and scenario state.
What you can do after
Builds executable API behavior tests that start the service, issue requests, and diagnose mismatches between expected and returned results.
How it connects
Connects Gherkin, behavior-driven development, Cucumber, integration testing, HTTP APIs, Resty, and httptest.

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.