Auto-generate mock implementations of Go interfaces with the mockgen tool so you never write fake code by hand.
Set strict expectations in tests such as a function must be called exactly once with a specific argument and fail automatically if it is not.
Wire mockgen into go:generate so mocks are regenerated automatically whenever an interface definition changes.
| golang/mock | sosedoff/pgweb | bytedance/sonic | |
|---|---|---|---|
| Stars | 9,366 | 9,356 | 9,382 |
| Language | Go | Go | Go |
| Setup difficulty | moderate | easy | easy |
| Complexity | 2/5 | 2/5 | 2/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
Repository is archived, new projects should use the maintained community fork at go.uber.org/mock.
GoMock is a testing tool for Go programs. The README states upfront that this repository is no longer maintained as of June 2023, and anyone looking for an actively supported version should use the community fork at go.uber.org/mock instead. For those who encounter this codebase: when developers write software, they often need to test one piece of code in isolation, without relying on other pieces that might be slow, unreliable, or not yet built. A common approach is to replace those dependencies with fakes called mocks, objects that pretend to be the real thing and let you specify exactly what they should return during a test. GoMock automates the creation of those fakes. The workflow has two parts. First, a command-line tool called mockgen reads your Go interface definitions and automatically generates the fake implementation code, so you do not have to write it by hand. Second, the gomock library provides functions you use inside your tests to set expectations, such as "this method should be called exactly once with the value 99 and should return 101." If the code under test calls the fake in any other way, the test fails automatically. The mockgen tool can read interfaces directly from source files or by analyzing your code through Go's reflection system. It produces standard Go source files you check into your project alongside your other code. This project was maintained by the Go team at Google and integrates with Go's built-in testing package. It works in any Go project and can be combined with code generation directives so mocks are regenerated automatically when interfaces change. Because the repository is archived, new projects should use the maintained fork mentioned above.
An archived Go testing tool that auto-generates fake implementations of interfaces so you can test one piece of code without starting real databases or services, use the community fork at go.uber.org/mock for new projects.
Mainly Go. The stack also includes Go.
License terms not stated in the explanation.
Setup difficulty is rated moderate, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.