The previous example used our custom mock objects. When you're working with a lot of interfaces, writing these can become cumbersome and error-prone. This is a place where generating code makes a lot of sense. Fortunately, there's a package called github.com/golang/mock/gomock that provides a generation of mock objects and gives us a very useful library to use in conjunction with interface testing.
This recipe will explore some of the functionality of gomock and will cover trade-offs on where, when, and how to work with and generate mock objects.
Getting ready
Configure your environment according to these steps:
- Refer to the Technical requirements section at the beginning of this chapter.
- Run the go get github.com/golang/mock/mockgen command.
How to do it...
These steps cover writing and running your application:
- From your Terminal...