Integration tests with Go and testcontainers

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

Our great sponsors
  • SonarLint - Clean code begins in your IDE with SonarLint
  • - Download’s Tech Salary Report
  • Scout APM - Truly a developer’s best friend
  • 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:

  • testcontainers-go

    Testcontainers is a Golang library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.


  • SonarLint

    Clean code begins in your IDE with SonarLint. Up your coding game and discover issues early. SonarLint is a free plugin that helps you find & fix bugs and security issues from the moment you start writing code. Install from your favorite IDE marketplace today.

  • 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