How to mock DB for unit tests?

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

SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  1. 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.

  2. SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
  3. 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.

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

  • Integration tests with Go and testcontainers

    6 projects | dev.to | 23 Jul 2022
  • Functional Programming in Go

    2 projects | news.ycombinator.com | 8 Nov 2024
  • Leverage Your Test Suite With testcontainers-go & docker-compose

    4 projects | dev.to | 4 Oct 2024
  • Integration Tests in Go with Cucumber, Testcontainers, and HTTPMock

    4 projects | dev.to | 11 Sep 2024
  • I Write Tests in Go

    1 project | news.ycombinator.com | 10 Apr 2024

Did you know that Go is
the 4th most popular programming language
based on number of references?