I'm currently unit testing a piece of code which uses an interface that contains a method with no input or output. Using testify's mock package, what is the proper way to write a mock implementation of this function?
Currently, I've written it as:
type A struct {
mock.Mock
}
func (a *A) DoSomething() {
_ = a.Called(nil)
}
Let's say you have something like this:
Now, using mockgen as outlined in this related answer of mine we can add the following bit:
This will generate a package under
bar(as inbar/mocks), which contains the generated mock/fake/spy object you'll want to use in your test like this:mockgen/gomock can do a lot more than just this, read more about it here. It seems like the repo was recently archived and moved, I suspect its replacement is pretty much a drop in replacement + some new functionality though.