gomock

module
v0.0.0-...-188e856 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2017 License: Apache-2.0

README

GoMock is a mocking framework for the Go programming language. It integrates well with Go's built-in testing package, but can be used in other contexts too.

Installation

Once you have installed Go, run these commands to install the gomock package and the mockgen tool:

go install github.com/CrowdStrike/gomock
go install github.com/CrowdStrike/mockgen

Documentation

After installing, you can use go doc to get documentation:

go doc github.com/CrowdStrike/gomock

Alternatively, there is an online reference for the package hosted on godoc.org here.

Running mockgen

The mockgen command is used to generate source code for a mock class given a Go source file containing interfaces to be mocked. It supports the following flags:

  • -source: The file containing interfaces to be mocked. You must supply this flag.

  • -destination: A file to which to write the resulting source code. If you don't set this, the code is printed to standard output.

  • -package: The package to use for the resulting mock class source code. If you don't set this, the package name is mock_ concatenated with the package of the input file.

  • -imports: A list of explicit imports that should be used in the resulting source code, specified as a comma-separated list of elements of the form foo=bar/baz, where bar/baz is the package being imported and foo is the identifier to use for the package in the generated source code.

  • -aux_files: A list of additional files that should be consulted to resolve e.g. embedded interfaces defined in a different file. This is specified as a comma-separated list of elements of the form foo=bar/baz.go, where bar/baz.go is the source file and foo is the package name of that file used by the -source file.

For an example of the use of mockgen, see the sample/ directory. In simple cases, you will need only the -source flag.

Writing Tests with mocks

TODO

Directories

Path Synopsis
GoMock - a mock framework for Go.
GoMock - a mock framework for Go.
MockGen generates mock implementations of Go interfaces.
MockGen generates mock implementations of Go interfaces.
model
Package model contains the data model necessary for generating mock implementations.
Package model contains the data model necessary for generating mock implementations.
An example package with an interface.
An example package with an interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL