To keep test doubles in sync with your interfaces, use go:generate directives in your .go files. You can use two different patterns:
Standard Directive
Add a directive directly above your interface. This is useful for single interfaces.
Batch Generation (Recommended for multiple interfaces)
If a package contains many interfaces, use the -generate flag once per package to speed up the process. Then, use the //counterfeiter:generate shorthand for each interface.
To run the generation, execute go generate ./... from your module root.
package foo
// Option 1: Standard directive
//go:generate go tool counterfeiter . MySpecialInterface
type MySpecialInterface interface {
DoThings(string, uint64) (int, error)
}
// Option 2: Batch generation (faster for many interfaces)
//go:generate go tool counterfeiter -generate
//counterfeiter:generate . MyOtherInterface
type MyOtherInterface interface {
DoOtherThings(string, uint64) (int, error)
}