How to mock DB for unit tests?

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
  • go-sqlmock

    Sql mock driver for golang to test database interactions

    I've never bothered with any ORM, but for mocking the underlying sql.DB I've been using https://github.com/DATA-DOG/go-sqlmock which is very simple and straightforward to use.

  • gnomock

    Test your code without writing mocks with ephemeral Docker containers 📦 Setup popular services with just a couple lines of code ⏱️ No bash, no yaml, only code 💻

    You could check out Gnomock (https://github.com/orlangure/gnomock). It offers a different approach than what you asked, but maybe it'll suit your use case. It allows to easily setup a real DB like postgres in a docker container and then delete ot when tests are done.

  • 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.

  • IAGD-Onlinesync

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