Skip to content
generate mock for type aliased mock
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

mockgo - mock generator for type aliased mock

mockgo generates a test mock for tye type.

Getting started

How to install or update.

$ go get -u

Generate mock for your types.

$ cd ~/go/src/
$ mockgo -pacakge TargetType1 TargetType2


$ mockgo {OPTIONS} -package {package name or relative path} [target classes...]


  • -fortest - generate mock for plain test, without +mock tag)

  • -mocksuffix - add Mock suffix to generated mock types

  • -noformat - write mock without formatting (goimports equivalent)

  • -output - specify output directory (default ., current directory)

  • -package - mandatory, specify a package where types are which generate mock for.

    starts with ./ or ../, you can use relative path for this.

  • -verbose - show verbose/debug messages to stderr

Target classes

Where [target classes...] accepts two forms of name to specify type.

  • OriginalTypename - Mock type name will be same with OriginalTypename

    When -mocksuffix given, OriginalTypenameMock is used for mock type.

  • OriginalTypename:MockTypename - Specify both original and mock type names

    -mocksuffix is ignored.

Advanced usage

Based component differential

for interface based component, -fortest and -mocksuffix will work well.

mockgo -package ./ -outdir . -fortest -mocksuffix Interface1 Interface2

for struct based component, this command will work well.

mockgo -package ../pkgA -outdir . Component1 Component2
You can’t perform that action at this time.