| tag | 9439c56d14531ae1b56b67b05ca8a57a671fcb94 | |
|---|---|---|
| tagger | Hesky Fisher <hesky@google.com> | Sat Jul 22 14:51:16 2017 |
| object | 13f360950a79f5864a972c786a10a50e44b69541 |
Arbitrarily naming the current version as 1.0.0. Backwards-incompatible changes will increment the major version.
| commit | 13f360950a79f5864a972c786a10a50e44b69541 | [log] [tgz] |
|---|---|---|
| author | Hesky Fisher <hesky.fisher@gmail.com> | Sat Jul 22 14:45:13 2017 |
| committer | GitHub <noreply@github.com> | Sat Jul 22 14:45:13 2017 |
| tree | fbc230c0a2b8e11b127de22bad85b4521cd156ae | |
| parent | 624477286d457cc1e1fa6d0e188e5965b58a2ec1 [diff] | |
| parent | dea6b4faed39e3cf900ad31554956a60f71a4d17 [diff] |
Merge pull request #93 from golang/restore_backwards_compatibility Restore backwards compatibility for controller.RecordCall.
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.
Once you have installed Go, run these commands to install the gomock package and the mockgen tool:
go get github.com/golang/mock/gomock go get github.com/golang/mock/mockgen
After installing, you can use go doc to get documentation:
go doc github.com/golang/mock/gomock
Alternatively, there is an online reference for the package hosted on GoPkgDoc here.
mockgen has two modes of operation: source and reflect. Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that may be useful in this mode are -imports and -aux_files.
Example:
mockgen -source=foo.go [other options]
Reflect mode generates mock interfaces by building a program that uses reflection to understand interfaces. It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols.
Example:
mockgen database/sql/driver Conn,Driver
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: A file containing interfaces to be mocked.
-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.
-build_flags: (reflect mode only) Flags passed verbatim to go build.
For an example of the use of mockgen, see the sample/ directory. In simple cases, you will need only the -source flag.
TODO: Brief overview of how to create mock objects and set up expectations, and an example.