When to mock and what to mock in a Web API?

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

Our great sponsors
  • ONLYOFFICE ONLYOFFICE Docs — document collaboration in your environment
  • CodiumAI - TestGPT | Generating meaningful tests for busy devs
  • InfluxDB - Access the most powerful time series database as a service
  • SonarLint - Clean code begins in your IDE with SonarLint
  • gomock

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

    Normally I like to generate everything with Mockgen and test it using table driven test.

  • dockertest

    Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.

    If your project is relatively simple and you can get away with recreating your scenarios against a real mock database and run other related services locally. It would be good to setup docker containers for your test scripts and write e2e tests. I believe e2e tests are harder but more useful in understanding/reasoning how users are impacted.


    ONLYOFFICE Docs — document collaboration in your environment. Powerful document editing and collaboration in your app or environment. Ultimate security, API and 30+ ready connectors, SaaS or on-premises

  • vcr

    Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

    If you had bit more complex workflows or less time - you could start using a VCR library to mock out API interactions and then continue with your dockerised DBs.

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