Using the Mockgen package to mock interfaces

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.0.25