whatisgithub

What is mock?

golang/mock — explained in plain English

Analysis updated 2026-06-24

9,366GoAudience · developerComplexity · 2/5Setup · moderate

In one sentence

An archived Go testing tool that auto-generates fake implementations of interfaces so you can test one piece of code without starting real databases or services, use the community fork at go.uber.org/mock for new projects.

Mindmap

mindmap
  root((GoMock))
    How it works
      mockgen reads interfaces
      Generates fake code
      gomock sets expectations
    Test features
      Call count checks
      Argument matching
      Return value control
    Integration
      Go testing package
      go generate support
    Status
      Archived June 2023
      Use go.uber.org/mock
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

What do people build with it?

USE CASE 1

Auto-generate mock implementations of Go interfaces with the mockgen tool so you never write fake code by hand.

USE CASE 2

Set strict expectations in tests such as a function must be called exactly once with a specific argument and fail automatically if it is not.

USE CASE 3

Wire mockgen into go:generate so mocks are regenerated automatically whenever an interface definition changes.

What is it built with?

Go

How does it compare?

golang/mocksosedoff/pgwebbytedance/sonic
Stars9,3669,3569,382
LanguageGoGoGo
Setup difficultymoderateeasyeasy
Complexity2/52/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Repository is archived, new projects should use the maintained community fork at go.uber.org/mock.

License terms not stated in the explanation.

So what is it?

GoMock is a testing tool for Go programs. The README states upfront that this repository is no longer maintained as of June 2023, and anyone looking for an actively supported version should use the community fork at go.uber.org/mock instead. For those who encounter this codebase: when developers write software, they often need to test one piece of code in isolation, without relying on other pieces that might be slow, unreliable, or not yet built. A common approach is to replace those dependencies with fakes called mocks, objects that pretend to be the real thing and let you specify exactly what they should return during a test. GoMock automates the creation of those fakes. The workflow has two parts. First, a command-line tool called mockgen reads your Go interface definitions and automatically generates the fake implementation code, so you do not have to write it by hand. Second, the gomock library provides functions you use inside your tests to set expectations, such as "this method should be called exactly once with the value 99 and should return 101." If the code under test calls the fake in any other way, the test fails automatically. The mockgen tool can read interfaces directly from source files or by analyzing your code through Go's reflection system. It produces standard Go source files you check into your project alongside your other code. This project was maintained by the Go team at Google and integrates with Go's built-in testing package. It works in any Go project and can be combined with code generation directives so mocks are regenerated automatically when interfaces change. Because the repository is archived, new projects should use the maintained fork mentioned above.

Copy-paste prompts

Prompt 1
I have a Go interface called UserRepository with GetUser and SaveUser methods. Use mockgen to generate a mock, then write a test that expects GetUser to be called once with ID 42 and return a specific test user.
Prompt 2
Show me how to add a go:generate directive so running go generate regenerates all gomock mocks in my project when interfaces change.
Prompt 3
My Go service calls an external payment API. Write a gomock test that verifies my checkout function calls Charge exactly once and retries once on a network error.

Frequently asked questions

What is mock?

An archived Go testing tool that auto-generates fake implementations of interfaces so you can test one piece of code without starting real databases or services, use the community fork at go.uber.org/mock for new projects.

What language is mock written in?

Mainly Go. The stack also includes Go.

What license does mock use?

License terms not stated in the explanation.

How hard is mock to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is mock for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.