Search⌘ K
AI Features

Making Executable Specifications Out of Our Features

Explore how to transform feature files into executable specifications using the godog library in Go. Learn to generate REST clients with go-swagger, implement step functions, and register them for end-to-end testing. Gain a practical understanding of designing critical test flows with unit, integration, and contract tests to improve your event-driven applications.

To make a feature file an executable specification, we will use the godog library, which is the official Cucumber library for Go. With this library, we can write a TestEndToEnd function that will be executed using the go test command.

We will also need clients for each of the REST APIs. Normally, E2E tests would involve interacting with some end user UI, but our little application has none to work with at the moment. The REST clients can be generated using the go-swagger tool, which can be installed along with the other tools we have used in this course by running the following command from the root of the code for this chapter:

make install-tools
Installing necessary tools

The actual command to generate the clients is then added to the generate.go file for each module. The added command looks something like the following, with added line breaks to make it easier to read:

//go:generate swagger generate client -q
-f ./internal/rest/api.swagger.json
-c storesclient
-m storesclient/models
--with-flatten=remove-unused
Command for generating the clients

The generate command in the previous listing will ...