Automatic Go package mock generation tool
Go Shell Other
Switch branches/tags
Nothing to show
Clone or download
qur Keep type behind build constraints
If we pick up a type from a file with build tags, then we should put the
related mock recorder into a file with the same tags. If we don't do this, then
they will be picked up at build time, and try to use the types that have been
hidden - causing the build to fail.
Latest commit b0df8b0 Aug 4, 2018
Failed to load latest commit information.
images/go1.10 Some tweaks to build setup Aug 3, 2018
lib Keep type behind build constraints Aug 4, 2018
mocktest Start work on getting things working with go 1.8 Apr 2, 2017
scenarios Add screnario to issue with using ssh library Mar 12, 2018
stdlib Update more import paths Jul 12, 2015
.gitignore More test enhancements Oct 1, 2013
.wrproject Use wharfrat to provide a dev environment Jul 5, 2018
doc.go Add sections to docs Nov 24, 2013

withmock / mocktest

What is this?

A pair of tools to automatically mock packages for testing with gomock

How do I install it?

As you might expect:

go get
go get

You will also need to install goimports (, and gomock (

How do I use it?

withmock allows an arbitrary command to be run, but will only setup the test environment for the package in the current directory. mocktest builds it's own command to be run, but can test multiple packages at the same time.

To configure which packages get mocked, you just add "// mock" to the end of your import in the test code. Then you can use with withmock or mocktest to actually run the test. To use withmock you simply prepend withmock to your normal test command, e.g.:

withmock go test

To use mocktest you specify the packages on the command line, so to test the current directory in the same manner as the above withmock command you can just run:


However, if you wanted to run a heirarchy of test you could run:

mocktest ./...

For more info see the documentation:

You can also check out the example.