Stage 02 · Test · Researched comparison
Best Go Mocking Libraries in 2026
go.uber.org/mock is the first pick for most teams. It is the maintained fork of the archived golang/mock project, generates type-safe mocks from interfaces, and works with the standard testing package. Teams that want hand-written fakes without code generation should look at matryer/moq, and teams testing HTTP handlers should look at httptest in the standard library or h2non/gock for client-side HTTP mocking.
By Shihab Mia
Published 27 Nov 2026 · 8 tools compared
We run no ads and no affiliate links at launch. The order of a list follows our published method. See how we score.
Prices are the starting prices vendors list publicly. Plans change, so confirm the current price on the vendor page before you buy.
Key takeaways
- All eight tools listed here are free and open source, so cost is not the deciding factor.
- go.uber.org/mock and matryer/moq both generate mock code from interfaces, but they differ in generated API style and workflow.
- Standard library packages net/http/httptest and database/sql/driver cover HTTP handler and SQL driver testing without third-party dependencies.
- Mocking libraries run locally in your build, so no test data is sent to a third-party web page.
Who each pick is for
- Teams that want generated, type-safe mocks from interfacesgo.uber.org/mock
- Developers who want minimal generated mocks with a simple APImatryer/moq
- Teams already using testify assertions that want runtime mockstestify/mock
- Projects that need mocks for interfaces, functions and structsmaxbrunsfeld/counterfeiter
- Testing code that makes outbound HTTP callsh2non/gock
- Testing HTTP handlers and servers with no third-party dependencynet/http/httptest
- Testing database code without a live databaseDATA-DOG/go-sqlmock
- Simple stubbing of HTTP responses in testsjarcoal/httpmock
Comparison
| Tool | Best for | Standout feature | Listed starting price | Free plan or trial |
|---|---|---|---|---|
| 1go.uber.org/mock | Teams that want generated, type-safe mocks from interfaces | Actively maintained fork of golang/mock | Free (open source) | Free plan |
| 2matryer/moq | Developers who want minimal generated mocks with a simple API | Small, readable generated code | Free (open source) | Free plan |
| 3testify/mock | Teams already using testify assertions that want runtime mocks | Same module as testify assert and require | Free (open source) | Free plan |
| 4maxbrunsfeld/counterfeiter | Projects that need mocks for interfaces, functions and structs | Can generate fakes for interfaces, functions and whole packages | Free (open source) | Free plan |
| 5h2non/gock | Testing code that makes outbound HTTP calls | Fluent API for matching method, URL and body | Free (open source) | Free plan |
| 6net/http/httptest | Testing HTTP handlers and servers with no third-party dependency | Part of the standard library | Free (open source) | Free plan |
| 7DATA-DOG/go-sqlmock | Testing database code without a live database | Implements database/sql/driver so code under test uses the real sql package | Free (open source) | Free plan |
| 8jarcoal/httpmock | Simple stubbing of HTTP responses in tests | Small API for registering canned responses | Free (open source) | Free plan |
How we picked
We selected projects that are currently maintained and that solve a distinct mocking job in Go: interface mock generation, runtime mocks, HTTP client stubbing, HTTP handler testing and SQL driver mocking. We checked licence terms, supported platforms and documented limits on the project repository and vendor pages. We did not run benchmarks or hands-on tests. Prices and plan terms can change, so confirm details on the project site before you commit.
The tools, one by one
go.uber.org/mock
Best for teams that want generated, type-safe mocks from interfaces

What it is and where it fits
This is the maintained successor to the archived golang/mock repository. It provides the gomock package for setting expectations in tests and the mockgen tool for generating mock implementations from interfaces. Generated mocks are type-safe, so a signature change in the interface breaks the build rather than the test at runtime.
mockgen supports source mode, reflect mode and package mode. Most teams wire it into a go:generate line or a Makefile target so mocks are regenerated with the code. The generated code is verbose, which means larger diffs and more files to review.
It runs anywhere Go runs, on Linux, macOS and Windows. The licence is Apache 2.0. Teams that dislike generated code in version control, or that prefer small hand-written fakes, should consider matryer/moq instead.
Standout: Actively maintained fork of golang/mock
Free (open source), as listed by the vendor (go.uber.org/mock website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Actively maintained fork of golang/mock
- gomock and mockgen cover generated mocks and expectations
Drawbacks
- Generated files add noise to diffs
- mockgen setup needs a build step or go:generate directive
Skip it if this limit matters to you: generated files add noise to diffs.
Verdict. A sensible pick for teams that want generated, type-safe mocks from interfaces.
Alternatives in this guide: matryer/moq, testify/mock, maxbrunsfeld/counterfeiter
matryer/moq
Best for developers who want minimal generated mocks with a simple API

What it is and where it fits
moq generates mock implementations of interfaces from a command-line call. The output is compact and readable, which keeps diffs small. Each generated mock exposes function fields that tests assign directly, so there is no separate expectation DSL to learn.
The tool is typically run through go:generate. It works with any Go module and does not require a runtime dependency in the generated file beyond the standard library and the target package.
The licence is MIT. It runs on any platform with a Go toolchain. Teams that need ordered call expectations, argument matchers and strict verification should compare it with go.uber.org/mock before committing.
Standout: Small, readable generated code
Free (open source), as listed by the vendor (matryer/moq website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Small, readable generated code
- simple command-line interface with go:generate support
Drawbacks
- Fewer expectation helpers than gomock
- generated mocks are less strict about call order by default
Skip it if this limit matters to you: fewer expectation helpers than gomock.
Verdict. A sensible pick for developers who want minimal generated mocks with a simple API.
Alternatives in this guide: go.uber.org/mock, testify/mock, maxbrunsfeld/counterfeiter
testify/mock
Best for teams already using testify assertions that want runtime mocks

What it is and where it fits
The mock package inside testify provides a Mock struct that records calls and returns configured values. Tests set expectations with On and AssertExpectations. Because there is no code generation, you write a small struct that embeds mock.Mock and implements the interface methods by hand.
This suits codebases that already depend on testify for assertions, since no extra module is needed. The trade-off is that the compiler cannot check that your mock matches the interface; a mismatch shows up as a failing test or a panic at runtime.
The module is MIT licensed and maintained on GitHub. It runs wherever Go runs. Teams that want compile-time safety from generated mocks should use go.uber.org/mock or matryer/moq instead.
Standout: Same module as testify assert and require
Free (open source), as listed by the vendor (testify/mock website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Same module as testify assert and require
- mock objects configured at runtime without code generation
Drawbacks
- Mocks are not type-checked against the interface
- expectation mistakes surface only at test runtime
Skip it if this limit matters to you: mocks are not type-checked against the interface.
Verdict. A sensible pick for teams already using testify assertions that want runtime mocks.
Alternatives in this guide: go.uber.org/mock, matryer/moq, maxbrunsfeld/counterfeiter
maxbrunsfeld/counterfeiter
Best for projects that need mocks for interfaces, functions and structs
What it is and where it fits
counterfeiter generates test doubles from interfaces, function types and packages. It is often used in projects that wrap third-party clients behind an interface and need a fake for the whole package surface.
Generated fakes record invocations and let tests supply return values and callbacks. The tool integrates with go:generate and can be configured to produce fakes for several targets in one run.
The licence is MIT. It runs on any platform with Go installed. The generated code is larger than moq output, so teams that want the smallest possible fakes may prefer a simpler generator. It is a good fit when the surface to fake is broad.
Standout: Can generate fakes for interfaces, functions and whole packages
Free (open source), as listed by the vendor (maxbrunsfeld/counterfeiter website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Can generate fakes for interfaces, functions and whole packages
- supports go:generate
Drawbacks
- Larger generated output
- configuration is more involved than single-interface generators
Skip it if this limit matters to you: larger generated output.
Verdict. A sensible pick for projects that need mocks for interfaces, functions and structs.
Alternatives in this guide: go.uber.org/mock, matryer/moq, testify/mock
h2non/gock
Best for testing code that makes outbound HTTP calls

What it is and where it fits
gock intercepts outbound HTTP requests made through net/http and returns configured responses. Tests declare expected requests with a chain of matchers and then assert that all expectations were met.
It is useful for client libraries and services that call external APIs, because tests run without network access and without a live server. Response bodies, status codes, headers and delays can all be set.
The licence is MIT. It runs on any Go platform. It does not mock inbound HTTP handlers; for that, use net/http/httptest. Teams that need to record and replay real traffic should look at a dedicated HTTP recording tool instead.
Standout: Fluent API for matching method, URL and body
Free (open source), as listed by the vendor (h2non/gock website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Fluent API for matching method, URL and body
- works with the standard net/http client
Drawbacks
- Only covers HTTP client traffic
- matching rules can grow complex for large APIs
Skip it if this limit matters to you: only covers HTTP client traffic.
Verdict. A sensible pick for testing code that makes outbound HTTP calls.
Alternatives in this guide: go.uber.org/mock, matryer/moq, testify/mock
net/http/httptest
Best for testing HTTP handlers and servers with no third-party dependency

What it is and where it fits
httptest provides ResponseRecorder and Server types for testing handlers and clients. A handler test calls the handler with a recorder and inspects the status code and body. A client test starts a real local server on a random port and points the client at it.
Because it ships with Go, there is no dependency to update and no licence to review. It is the default choice for handler tests and pairs well with generated mocks for the service layer behind the handler.
It runs on every platform Go supports. It does not replace an interface mocking library; it complements one. Teams testing non-HTTP code still need a generator or a runtime mock package.
Standout: Part of the standard library
Free (open source), as listed by the vendor (net/http/httptest website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Part of the standard library
- no module to add or maintain
Drawbacks
- Covers HTTP only
- no interface mocking or expectation framework
Skip it if this limit matters to you: covers HTTP only.
Verdict. A sensible pick for testing HTTP handlers and servers with no third-party dependency.
Alternatives in this guide: go.uber.org/mock, matryer/moq, testify/mock
DATA-DOG/go-sqlmock
Best for testing database code without a live database

What it is and where it fits
go-sqlmock provides a mock driver for database/sql. Tests declare expected queries, arguments and result rows, and the code under test runs against the mock connection as if it were a real database.
This keeps unit tests fast and free of external services. It is commonly used to test repository layers and query builders. Because matching is regex-based, small SQL formatting changes can break expectations, so keep queries stable or use query matchers carefully.
The licence is MIT. It runs on any Go platform. It does not replace integration tests against a real database; use it for unit-level coverage and keep a smaller set of integration tests for real SQL.
Standout: Implements database/sql/driver so code under test uses the real sql package
Free (open source), as listed by the vendor (DATA-DOG/go-sqlmock website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Implements database/sql/driver so code under test uses the real sql package
- matches queries and arguments
Drawbacks
- SQL matching is regex-based and can be brittle
- does not validate real database behaviour
Skip it if this limit matters to you: SQL matching is regex-based and can be brittle.
Verdict. A sensible pick for testing database code without a live database.
Alternatives in this guide: go.uber.org/mock, matryer/moq, testify/mock
jarcoal/httpmock
Best for simple stubbing of HTTP responses in tests

What it is and where it fits
httpmock replaces the default HTTP transport with a mock that returns registered responses. Tests register a method and URL with a status code and body, then call the code under test.
It is lighter than gock in feature scope, which suits small test suites that only need canned responses. Activation is global for the process, so tests should deactivate it with a defer to avoid leaking state between tests.
The licence is MIT. It runs on any Go platform. It covers outbound HTTP only. Teams that need request sequence matching, delays or richer matchers should compare it with gock.
Standout: Small API for registering canned responses
Free (open source), as listed by the vendor (jarcoal/httpmock website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Small API for registering canned responses
- integrates with the default HTTP transport
Drawbacks
- Less expressive matching than gock
- global transport activation needs careful cleanup
Skip it if this limit matters to you: less expressive matching than gock.
Verdict. A sensible pick for simple stubbing of HTTP responses in tests.
Alternatives in this guide: go.uber.org/mock, matryer/moq, testify/mock
Who should use what
Teams with many interfaces and a strict CI pipeline should use go.uber.org/mock for generated, type-checked mocks. Teams that want small readable fakes and a simple generator should use matryer/moq. Teams already on testify can add testify/mock without a new module. Teams testing HTTP handlers should start with net/http/httptest, add gock or httpmock for outbound calls, and use DATA-DOG/go-sqlmock for repository unit tests.
Questions to settle before you buy
What to check before you buy
- Confirm the project is actively maintained by checking recent commits and releases on its repository.
- Check the licence (Apache 2.0, MIT or BSD) against your organization's policy.
- Decide whether generated mocks belong in version control or should be built in CI.
- Verify the library works with your Go version and module setup.
- Check that the mocking approach matches the layer under test: interface, HTTP client, HTTP handler or SQL driver.
FAQ
Do I need a mocking library if I use interfaces in Go?
No. Small hand-written fakes are often enough. A library helps when interfaces are large, when many mocks are needed, or when you want generated code to stay in sync with interface changes.
Is golang/mock still maintained?
The original golang/mock repository is archived. Use go.uber.org/mock, the maintained fork, which provides the gomock package and mockgen tool under the same style of API.
Can these libraries mock HTTP calls?
gock and httpmock stub outbound HTTP client calls. net/http/httptest tests inbound handlers and servers. They solve different problems and are often used together in one test suite.
Are these tools free?
All eight tools listed are free and open source under licences such as Apache 2.0, MIT or BSD. There are no paid tiers for the libraries themselves.
Do these tools send my code or test data anywhere?
No. They run locally as part of your Go build and test process. Nothing is uploaded to a third-party service, so there is no risk of leaking code or test data through the tool itself.
Sources we checked
Method: how we score · editorial policy.
Change log. First published 27 Nov 2026.