mockery

Go mock code generator that creates type-safe mock implementations of Go interfaces for unit testing. Run mockery on a Go interface and it generates a complete mock struct with configurable method stubs, call tracking, and testify-based assertions. The standard Go mocking tool alongside testify/mock — used extensively in Go projects for unit testing with dependency injection.

Evaluated Mar 06, 2026 (0d ago) v2.x
Homepage ↗ Repo ↗ Developer Tools go mocking code-generation testing interface mock cli
⚙ Agent Friendliness
66
/ 100
Can an agent use this?
🔒 Security
98
/ 100
Is it safe for agents?
⚡ Reliability
81
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

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

🔒 Security

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

Code generation tool. Generated code has no security surface. No external calls.

⚡ Reliability

Uptime/SLA
90
Version Stability
78
Breaking Changes
72
Error Recovery
85
AF Security Reliability

Best When

You're writing Go unit tests for interface-based code and want generated type-safe mocks without boilerplate — mockery is the standard Go mock generator.

Avoid When

Your code doesn't use interfaces (refactor first), or you want programmatic (not generated) mocking (use gomock).

Use Cases

  • Generate mock implementations of Go interfaces for unit testing without writing boilerplate mock code manually
  • Create type-safe test doubles for Go services that implement specific interfaces (DatabaseRepository, APIClient)
  • Use generated mocks with testify's mock.Called() and AssertExpectations() for behavior verification in Go tests
  • Regenerate mocks automatically in CI when interface definitions change using mockery in generate mode
  • Mock external service clients (HTTP, gRPC, database) in Go unit tests to isolate business logic testing

Not For

  • Mocking concrete types (only interfaces) — Go's interface-based design must be followed for mockery to work
  • Teams not using testify — mockery generates testify-based mocks by default; custom backends require configuration
  • Dynamic mocking without code generation — consider gomock for programmatic mock setup without generated code

Interface

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

Authentication

Methods: none
OAuth: No Scopes: No

Code generation CLI tool. No authentication required.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

BSD license.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • mockery v2 uses .mockery.yaml config file for multi-interface generation — without it, must pass interface names on CLI each time
  • Generated mocks must be regenerated when interface changes — stale mocks cause compilation failures; add mockery generate to CI or use go:generate
  • mock.On() requires exact argument matching by default — use mock.MatchedBy() for flexible argument matching on complex types
  • AssertExpectations(t) must be deferred in tests — forgetting this means unused mock expectations don't cause test failures
  • mockery generates mocks in a 'mocks' subdirectory by default — directory structure affects import paths; configure output in .mockery.yaml
  • Generic interface mocking requires mockery v2.26+ — older versions don't support Go generics; upgrade mockery for generics support

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for mockery.

$99

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

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