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
