gomock
Go mock generation and testing framework. gomock generates mock implementations of Go interfaces using the mockgen tool — run mockgen on an interface file to get a type-safe mock that records calls and allows expectations. The most widely used Go mocking library. Forked to uber-go/mock (maintained) after the original google/gomock became unmaintained.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Local testing library — no network calls. No sensitive data exposure.
⚡ Reliability
Best When
You have Go agent code that depends on interfaces and want compile-time verified mocks with call expectation assertions — gomock's EXPECT() pattern catches incorrect argument usage at test time.
Avoid When
Your agent code depends on concrete types or HTTP clients — restructure around interfaces first, or use testify/mock for lighter-weight mocking without code generation.
Use Cases
- • Generate type-safe mocks for Go interfaces used by agent code — database clients, HTTP clients, external service adapters
- • Write unit tests for Go agent services that depend on interfaces — replace real implementations with mocks that verify call patterns
- • Assert expected method calls with specific arguments using EXPECT() — verify agent code calls downstream services with correct parameters
- • Return controlled responses from mock methods — simulate success, errors, and edge cases for agent error handling tests
- • Use InOrder() to verify agent code calls methods in the expected sequence without flaky timing dependencies
Not For
- • Mocking concrete types (structs) — gomock requires interfaces; refactor concrete dependencies to interfaces first
- • HTTP request mocking — use httptest or gock for HTTP-level mocking without generating interface mocks
- • Teams preferring testify/mock — testify has a simpler API for basic mocking without code generation
Interface
Authentication
Local testing library — no external auth or network calls.
Pricing
Apache 2.0 open source. Currently maintained as uber-go/mock; original google/gomock is archived.
Agent Metadata
Known Gotchas
- ⚠ gomock requires interfaces — agent code using concrete struct types must be refactored to use interfaces before gomock can mock dependencies
- ⚠ mockgen generates code that must be committed — regenerating mocks after interface changes requires running 'go generate ./...' and committing the updated mock files
- ⚠ EXPECT() calls must match actual calls or the test panics — using AnyTimes() too liberally masks agent code that makes unexpected calls; prefer exact Times(n) assertions
- ⚠ ctrl.Finish() must be called at test end to verify all expectations were met — use defer ctrl.Finish() or t.Cleanup(ctrl.Finish) immediately after creating the controller
- ⚠ Importing uber-go/mock vs google/gomock — ensure all imports use the same fork; mixing imports from both forks in a project causes compile errors
- ⚠ Mock methods with context.Context first argument — use gomock.Any() for context matching in most tests, or ctx matchers for context-value-specific assertions
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for gomock.
Scores are editorial opinions as of 2026-03-06.