Integration tests with Go and testcontainers

This page summarizes the projects mentioned and recommended in the original post on dev.to

SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • First, let's describe the service itself. Service in Github. The service uses gorilla/mux and Postgres. It implements a clean architecture and has such file structure:

  • SaaSHub

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

    SaaSHub logo
  • testcontainers-go

    Testcontainers for Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers that should be run as part of a test and clean up those resources when the test is done.

    testcontainers

  • testfixtures

    Ruby on Rails like test fixtures for Go. Write tests against a real database

    To solve the problem we will use testfixtures. Create a folders fixtures и fixtures/storage and put a file users.yaml inside:

  • Testify

    A toolkit with common assertions and mocks that plays nicely with the standard library

    As you may notice each test has a common part. To optimise our code and avoid duplication we will use testsuites from the testify library. This tool helps us to describe actions we need to take before each test.

  • httpmock

    HTTP mocking for Golang

    We will use httpmock for this purpose. Inside function setupSuite(), where we created useCase and provided nil as a billingClient now we will pass mocked http client:

  • All code samples can be found here

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

  • How to mock DB for unit tests?

    4 projects | /r/golang | 8 Feb 2021
  • 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 konow that Go is
the 4th most popular programming language
based on number of metions?