mockery
Mockery is a Go code generator that automatically creates mock implementations of interfaces for testing. It integrates with the popular testify/mock package to eliminate boilerplate when writing unit tests.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | vektra/mockery |
| Owner | vektra |
| Primary language | Go |
| License | BSD-3-Clause — OSI-approved |
| Stars | 7.1k |
| Forks | 454 |
| Open issues | 53 |
| Latest release | v3.7.1 (2026-06-12) |
| Last updated | 2026-06-22 |
| Source | https://github.com/vektra/mockery |
What mockery is
Mockery parses Go interface definitions and generates mock structs compatible with stretchr/testify/mock, supporting assertion and expectation patterns. The tool operates via CLI with configuration support and offers template-based customization for generated code.
Get the mockery source
Clone the repository and explore it locally.
git clone https://github.com/vektra/mockery.gitcd mockery# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Ensure Go version compatibility by checking go.mod constraints; README does not specify minimum Go version, requires manual verification.
- Configure mockery via CLI flags or configuration files; review documentation at vektra.github.io/mockery for exact syntax and options.
- Integrate mock generation into build pipeline using task runner (taskfile.dev) or go generate directives to keep mocks current.
- Test generated mocks with testify/mock to confirm assertion patterns and call expectations work as intended in your test suite.
- Review generated mock code before committing to catch potential issues; consider using `go generate` comments to track which interfaces are mocked.
When to avoid it — and what to weigh
- You require non-Go language mock generation — Mockery is Go-specific and does not generate mocks for other languages.
- Your testing strategy does not use interfaces — Mockery generates mocks from Go interfaces; code without interface boundaries cannot be mocked this way.
- You use a test framework incompatible with testify/mock assertions — Generated mocks assume testify/mock semantics; integration with other assertion libraries may require custom templates.
- You need mocks for unexported or non-interface types — Mockery only generates mocks for exported Go interfaces, not for concrete types or private definitions.
License & commercial use
Licensed under BSD-3-Clause (New/Revised), a permissive OSI-approved license. Allows commercial use, modification, and distribution with attribution and liability disclaimers.
BSD-3-Clause is a permissive license compatible with commercial projects. No known restrictions on use in proprietary codebases. Recommend legal review of license text for attribution requirements specific to your deployment.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
Mockery is a build-time code generator; no runtime security exposure. Generated mocks do not introduce new attack surface in production binaries. Verify integrity of the mockery binary via checksum or reproducible builds if deploying in restricted environments. No known CVEs visible in provided data.
Alternatives to consider
GoMock (golang/mock)
Official Go team-affiliated tool using code generation; generates mocks compatible with GoMock's controller pattern and gomock matchers. Different assertion API than testify/mock.
github.com/stretchr/testify/mock (manual mocks)
Testify provides a mock package but requires hand-written mock structs. Mockery automates this but both rely on same assertion library.
github.com/matryer/moq
Lightweight alternative for generating mocks inline; smaller footprint and different code generation approach, but less feature-rich than mockery.
Build on mockery with DEV.co software developers
Mockery reduces test boilerplate and keeps mocks in sync with interface changes. Evaluate it in your next Go project or let our team integrate it into your testing pipeline.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
mockery FAQ
What Go versions does mockery support?
Can mockery generate mocks for types outside my project?
How do I customize the generated mock code?
Is mockery suitable for continuous integration?
Work with a software development agency
From first prototype to production, DEV.co delivers software development services around tools like mockery. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source testing and beyond.
Ready to streamline your Go testing?
Mockery reduces test boilerplate and keeps mocks in sync with interface changes. Evaluate it in your next Go project or let our team integrate it into your testing pipeline.