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.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Code generation tool. Generated code has no security surface. No external calls.
⚡ 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
Authentication
Code generation CLI tool. No authentication required.
Pricing
BSD license.
Agent Metadata
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.
Scores are editorial opinions as of 2026-03-06.