explaingit

vektra/mockery

7,104GoAudience · developerComplexity · 2/5Setup · easy

TLDR

A code generation tool for Go that reads your interfaces and automatically writes mock objects for unit tests, eliminating repetitive boilerplate so you can focus on what the test actually checks.

Mindmap

mindmap
  root((mockery))
    What it does
      Reads Go interfaces
      Generates mock code
      Eliminates boilerplate
    Tech Stack
      Go language
      testify mock
      taskfile.dev
    Use Cases
      Unit test isolation
      Verify method calls
      Fake slow dependencies
    Audience
      Go developers
      Test authors
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Generate ready-to-use mock structs for any Go interface so you can test a function without its real dependencies.

USE CASE 2

Set expectations on method calls in tests, verify a database method was called exactly once with the right arguments.

USE CASE 3

Replace a slow external API or file system with a fast, controllable fake during unit testing.

USE CASE 4

Drop generated mocks into table-driven tests to cover success and error paths without real infrastructure.

Tech stack

Gotestify/mocktaskfile.dev

Getting it running

Difficulty · easy Time to first run · 30min

Install the mockery binary via go install or brew, then run it against your Go interface files.

In plain English

Mockery is a code generation tool for Go developers who write automated tests. In Go, when you want to test a piece of code in isolation, you often need a fake version of a dependency, called a mock, that you can control in your test. Writing these mock objects by hand is repetitive and error-prone. Mockery reads your Go interfaces and generates that boilerplate code for you automatically. The generated mocks are built on top of the testify/mock package, which is a widely used Go testing library. Once mockery generates a mock for an interface, you can use it in your tests to set expectations, verify calls were made, and return specific values without needing the real implementation. The repository README is brief and points to a separate documentation site for full usage details, configuration options, and examples. It notes that development tasks are managed with taskfile.dev. The project has accumulated over 7,100 GitHub stars, suggesting it is widely adopted in the Go testing ecosystem, but the README itself does not describe configuration options or advanced features in detail.

Copy-paste prompts

Prompt 1
I have a Go interface called UserRepository with FindByID and Save methods. Show me how to configure mockery to generate mocks for it and use them in a table-driven test.
Prompt 2
My Go service calls an external payment API. How do I use mockery to mock that dependency and test my service without making real HTTP requests?
Prompt 3
What is the difference between the --inpackage flag and generating mocks in a separate mocks/ directory in mockery, and which should I choose?
Prompt 4
How do I set up a mockery.yaml config file so I can run one command to regenerate all mocks in my Go project?
Prompt 5
How do I use a mockery-generated mock to return different values on the first and second call to the same method?
Open on GitHub → Explain another repo

← vektra on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.