gomock - early attempt at a mocking library

271 views
Skip to first unread message

John Beisley

unread,
Mar 13, 2011, 10:29:46 PM3/13/11
to golang-nuts
Hi,

I've been waiting for a mocking library for Go unit tests to be
written, but as yet I've not seen any turn up in any searches, so I
gave up waiting and wrote a quick attempt at one. This library is not
in a feature-complete state, but I would like to put it out early
before I invest too much time into it in order to get some opinions
and suggestions on how I could better the approach taken in this
library.

It is available via:

https://github.com/huin/gomock

goinstall github.com/huin/gomock

Or in Go code with: import "github.com/huin/gomock"

The objective is to testing calls made upon objects that fulfill a
given interface. This requires code generation for a mock type per
interface type that needs to be mocked. Currently this must be written
by hand, but hopefully a code-generator can be written at some stage.

Features that are obviously missing in this library at present:

* A complete Eq() comparator that can manage more than a few types.
* A more complete set of comparators.
* Any kind of optimization (if that's even desirable).
* Integration with test suites other than the "testing" package in the
Go standard library.

Possible features might include setting constraints upon expected call
order.

Thoughts/opinions?

Thanks,

- John

David Symonds

unread,
Mar 13, 2011, 10:55:43 PM3/13/11
to John Beisley, golang-nuts
Interesting. I've also written a mocking framework called GoMock. It's
got a very similar approach to yours (interface-based). It's got a
code generator too, which handles a bunch of interesting non-trivial
edge cases.

I should tidy it up and release it.


Dave.

John Beisley

unread,
Mar 13, 2011, 11:20:19 PM3/13/11
to golang-nuts
On Mar 13, 7:55 pm, David Symonds <dsymo...@golang.org> wrote:
> Interesting. I've also written a mocking framework called GoMock. It's
> got a very similar approach to yours (interface-based). It's got a
> code generator too, which handles a bunch of interesting non-trivial
> edge cases.

Heh, I was slightly worried that the work might already exist. Keep me
posted, as it will likely either be beneficial for either:

* the codebases to merge to bring the best features of both together
(that is assuming your code doesn't already have a superset of
beneficial features),
* my code to change name to avoid confusion.

- John

David Symonds

unread,
Mar 13, 2011, 11:24:26 PM3/13/11
to John Beisley, golang-nuts

I'm going to aim to push something out this week.
Bug me directly if it gets to the end of the week and I haven't posted
a follow-up.


Dave.

David Symonds

unread,
Mar 16, 2011, 8:26:07 PM3/16/11
to John Beisley, golang-nuts
Okay, I've released GoMock as open source here:
http://code.google.com/p/gomock/

It builds and runs, but isn't particularly easy to use right now.
I'll work on polishing the sample code and providing some useful
documentation over the next week or two.


Dave.

Reply all
Reply to author
Forward
0 new messages