GoMock is a mocking framework for the Go programming language that integrates with Go's built-in testing package while remaining flexible enough for use in other contexts. The framework provides the mockgen tool, a code generation utility that automatically creates mock implementations of Go interfaces, enabling developers to write unit tests with test doubles and verify behavioral expectations.
The mockgen tool operates in two distinct modes. Source mode generates mock interfaces directly from Go source files by parsing the code, making it suitable when you have direct access to interface definitions. Reflect mode uses runtime reflection to understand interfaces by building and executing a program that inspects them, which proves useful when working with imported packages or when source code is not readily available. Both modes support extensive customization through command-line flags that control output location, package naming, import handling, and mock naming conventions.
The framework supports numerous configuration options through its command-line interface. Developers can specify source files to mock, designate output destinations for generated code, customize package names for generated mocks, explicitly declare imports, reference auxiliary files for resolving embedded interfaces, and apply custom names to generated mock implementations. Additional flags enable copyright header injection, control over package documentation comments, and debugging capabilities. For reflect mode specifically, developers can pass build flags, generate reflection programs without execution, or execute pre-generated reflection programs.
GoMock integrates seamlessly with Go's testing infrastructure through its controller mechanism. When using Go 1.14 or later with mockgen 1.5.0 and above, developers no longer need to explicitly call ctrl.Finish() when passing a testing.T into gomock.NewController(t), as cleanup is automatically registered through Go's built-in Cleanup function. The framework provides matchers for behavioral verification and allows customization of failure messages by modifying matcher output and object string representations.
The repository has been classified across multiple domains including interface mocking, automatic code generation, unit testing, test doubles, dependency injection, and behavioral verification. GitGenius data indicates the repository links to golang/go, clickhouse/clickhouse, and immich-app/immich through overlapping contributors, suggesting active use across diverse projects. Issue and pull request response latency metrics show a median of 27444.1 hours and mean of 27554.2 hours, with tracked issues primarily categorized as feature requests and questions.
A critical update from June 2023 indicates that this repository and tool are no longer maintained. The README explicitly directs users to go.uber.org/mock, which is a maintained fork of the original GoMock project. This transition represents a significant shift in the project's maintenance status, with the Uber-maintained version becoming the recommended choice for new projects and ongoing development. Despite the maintenance status change, the original repository remains a reference implementation and historical record of the GoMock framework's design and functionality.