Using mockery with go generate

This is a simple example of how to use mockery with go generate. It is my preferred way of generating mocks, because the mocks configuration is co-located with the interface definition.

  1. Install mockery
go install # use latest version
  1. Add a go:generate comment to your interface
//go:generate mockery -name=MyInterface -output=mocks -outpkg=mocks -case=underscore
type MyInterface interface {
  1. Run go generate
go generate ./...

Mockery -