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.

Evaluated Mar 06, 2026 (0d ago) v1.6+
Homepage ↗ Repo ↗ Developer Tools go testing mocking interfaces mockgen open-source unit-testing
⚙ Agent Friendliness
67
/ 100
Can an agent use this?
🔒 Security
89
/ 100
Is it safe for agents?
⚡ Reliability
86
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
82
Auth Simplicity
100
Rate Limits
98

🔒 Security

TLS Enforcement
90
Auth Strength
90
Scope Granularity
88
Dep. Hygiene
88
Secret Handling
90

Local testing library — no network calls. No sensitive data exposure.

⚡ Reliability

Uptime/SLA
88
Version Stability
85
Breaking Changes
82
Error Recovery
88
AF Security 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

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Local testing library — no external auth or network calls.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

Apache 2.0 open source. Currently maintained as uber-go/mock; original google/gomock is archived.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

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.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered