CheckOps home

Tools directory

G

CheckOps

GoMock (uber-go/mock)

GoMock is an Apache-2.0 mocking framework for Go, maintained by Uber after the original golang/mock was archived, with the mockgen code generator and a gomock controller for expectations.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

GoMock is a mocking framework for Go that integrates with the built-in testing package. The original project at golang/mock was archived, and Uber maintains the continuation at go.uber.org/mock, which is now the recommended version.

The mockgen tool generates mock implementations from Go interfaces, either from source files (-source) or from a package and interface names. In tests you create a gomock.Controller, construct the generated mock, and set expectations with EXPECT().Method(args).Return(values), using matchers such as gomock.Any(), gomock.Eq() and custom matchers, call counts (Times, AnyTimes), ordering (gomock.InOrder) and actions (DoAndReturn). Unmet or unexpected calls fail the test automatically. mockgen can be wired into go generate so mocks stay in sync with interfaces. Version 0.6.0 was released on 18 August 2025, with commits continuing in August 2026.

The source code is at uber-go/mock on GitHub under the Apache-2.0 licence, with about 3,400 stars; the most recent commit was on 25 August 2026.

Features

  1. Code generation: mockgen creates type-safe mocks from interfaces.
  2. Expectations: EXPECT() with matchers, counts and ordering.
  3. go generate integration: Keep mocks in sync with interfaces.
  4. Maintained fork: Uber’s continuation of the archived golang/mock.

Pros

  1. Free to use: Open source under the Apache-2.0 licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 25 August 2026.
  3. Community: About 3,400 GitHub stars.

Cons

  1. Generated code to maintain: Mocks must be regenerated when interfaces change.
  2. Can encourage over-specification: Strict expectations make tests brittle if overused.
go install go.uber.org/mock/mockgen@latest
mockgen -source=store.go -destination=mocks/store_mock.go -package=mocks
func TestCheckout(t *testing.T) {
    ctrl := gomock.NewController(t)
    store := mocks.NewMockStore(ctrl)
    store.EXPECT().Save(gomock.Any()).Return(nil).Times(1)

    svc := NewCheckout(store)
    if err := svc.Place(Order{Total: 100}); err != nil {
        t.Fatal(err)
    }
}

Resources:

Pricing

GoMock (uber-go/mock) is free and open source under the Apache-2.0 licence.

  1. Go teams wanting generated, type-safe mocks with strict expectations.
  2. Codebases migrating from golang/mock.

Conclusion

GoMock, now maintained by Uber, is the standard generated-mock framework for Go.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with GoMock (uber-go/mock) side by side.