Quick-start guide

Installing moqueries

$ go install moqueries.org/cli/moqueries@latest

Generating mocks

Mocks are generated by directly invoking moqueries from your terminal, but typically you want to capture the command in a //go:generate directive. The following directive (in a working example here) generates a mock for Go’s ubiquitous io.Writer interface:

//go:generate moqueries --import io Writer

Based on the name of the type being mocked, the mock is written to a file called moq_writer_test.go in the same directory containing this directive. Also note that since we presumably didn’t put this directive in Go’s standard library io package, we have to include a --import io option so that Moqueries can find the type.

Generating mocks for function types is just as easy. In the same example (a few lines further down), we put a Go generate directive directly above the type definition (the best place for the directive unless you are mocking third-party types):

//go:generate moqueries IsFavorite

type IsFavorite func(n int) bool