Open petergtz opened 5 years ago
Hi Peter, thanks for getting in touch!
In the 2 years since I've written this, I've made my peace with writing mocks by hand (using testify's mock.Mock). I miss Mockito, but after writing the article I figured that generators were too clumsy to bother. I should definitely revisit pegomock, though.
What would be your preferred way to fail a test when mock verification fails?
Well, as you know, testify's mock.Mock recommends myDependency.AssertExpectations(t). It could be worse.
In the spirit of Mockito, I think I'd prefer something like mock.AssertExpectations(t, myDependency, myOtherDependency, myThirdDependency). That ought to be fairly easy.
Not sure I have much to offer. I haven't thought it through, really.
On Tue, 15 Jan 2019 at 21:22, Peter Götz notifications@github.com wrote:
Hi @elefevre https://github.com/elefevre, I just stumbled upon your mock tool evaluation and saw you also evaluated pegomock.
Note that you can generate mocks also from a main package, just use --use-experimental-model-gen. It's not quite up to par with the default method, but it's quite good. See also https://github.com/petergtz/pegomock#generating-mocks-with---use-experimental-model-gen
It also requires calling pegomock.RegisterMockTestingT(t), which is rather ugly.
What would be your preferred way to fail a test when mock verification fails?
I'd be happy to help you get your Mockito for Go back. It was the motivation for me to write Pegomock :-).
Thanks, Peter
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/leboncoin/golang-mock-tools/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVBXkbtYwNdsWPNEd6bBNH3WdBNUb61ks5vDjiHgaJpZM4aBvcW .
Hey Eric,
Thanks for getting back to me. Yea, feel free to have another look at Pegomock. Agree that generators feel clumsy at times. I found it to be bearable though, given how much flexibility I get from Pegomock.
I think what you might like is the fact that you don't need a global fail handler anymore. You can do e.g.
func TestUsingMocks(t *testing.T) {
mock := NewMockPhoneBook(pegomock.WithT(t))
// use your mock here
}
Or you can obviously also provide your own fail handler. The good part is that it's not global anymore and every mock can have its own fail handler.
Another goodie that I added since your evaluation is generated matchers for the types you use in interfaces. So a lot less typing.
Well, again, feel free to have another look. If you still prefer writing the mocks by hand using testify, that's obviously also perfectly fine :-). Feel free to close this issue in that case.
Cheers
Hi @elefevre, I just stumbled upon your mock tool evaluation and saw you also evaluated pegomock.
Note that you can generate mocks also from a main package, just use
--use-experimental-model-gen
. It's not quite up to par with the default method, but it's quite good. See also https://github.com/petergtz/pegomock#generating-mocks-with---use-experimental-model-genWhat would be your preferred way to fail a test when mock verification fails?
I'd be happy to help you get your Mockito for Go back. It was the motivation for me to write Pegomock :-).
Thanks, Peter