Behavior testing using Go
Behavior testing or integration testing is a good method of performing end-to-end black box testing. One popular framework for this type of testing is cucumber (https://cucumber.io/), which uses the Gherkin language to describe the steps to a test in English and then implement those steps in code. Go has a cucumber library as well (github.com/DATA-DOG/godog
). This recipe will explore using godog
package to write behavior tests.
Getting ready
Configure your environment according to these steps:
- Refer to the Getting ready section of the Mocking using the standard library recipe of this chapter.
- Run the
go get github.com/DATA-DOG/godog
command. - Run the
go get github.com/DATA-DOG/godog/cmd/godog
command.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter8/bdd
directory and navigate to it. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter8/bdd or use this as an exercise to...