DEV.co
Open-Source Testing · vektra

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.

Source: GitHub — github.com/vektra/mockery
7.1k
GitHub stars
454
Forks
Go
Primary language
BSD-3-Clause
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryvektra/mockery
Ownervektra
Primary languageGo
LicenseBSD-3-Clause — OSI-approved
Stars7.1k
Forks454
Open issues53
Latest releasev3.7.1 (2026-06-12)
Last updated2026-06-22
Sourcehttps://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.

Quickstart

Get the mockery source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/vektra/mockery.gitcd mockery# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Unit testing Go services with interface-based dependencies

Mockery eliminates manual mock struct boilerplate for testing code that depends on interfaces, reducing maintenance overhead as interfaces evolve.

CI/CD pipeline integration for Go projects

Automate mock generation as part of build tasks using taskfile.dev or standard Go tooling, ensuring mocks stay synchronized with interface changes.

Large codebases with frequent interface refactoring

Regenerating mocks on-demand prevents stale test doubles and drift between interface definitions and mock implementations.

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.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

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.

Software development agency

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.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

mockery FAQ

What Go versions does mockery support?
Not clearly stated in provided data. Check the go.mod file in the repository or GitHub releases for minimum Go version requirements.
Can mockery generate mocks for types outside my project?
Mockery operates on Go packages and interfaces you specify; it can generate mocks for exported interfaces from any imported package, but behavior with vendored or external code requires testing.
How do I customize the generated mock code?
Mockery supports template-based customization; refer to documentation at vektra.github.io/mockery for template syntax and examples.
Is mockery suitable for continuous integration?
Yes. Integrate via task runner or go generate; CI pipelines can regenerate mocks and fail builds if they drift from interface definitions, catching out-of-sync mocks early.

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.