How do you write/generate mocks for testing?

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • mockery

    A mock code autogenerator for Go (by vektra)

    My bread and butter is mockery (https://github.com/vektra/mockery). It has a few shortcomings (a config would be really nice in my project) which should be fixed in v3 (https://github.com/vektra/mockery#v3).

  • moq

    Interface mocking tool for go generate (by matryer)

    Currently trying out https://github.com/matryer/moq for the first time, and quite positive so far. Haven't pushed it enough yet to give a real opinion.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

  • gomock

    Discontinued GoMock is a mocking framework for the Go programming language. (by golang)

    Currently migrating from moq to https://github.com/golang/mock

  • minimock

    Powerful mock generation tool for Go programming language

  • counterfeiter

    A tool for generating self-contained, type-safe test doubles in go

    counterfeiter is another tool, it creates mocks, stubs and spies; here is a short blog I wrote covering it.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts