With the following Dockerfile we can easily spin up a docker container that will run the tests:

FROM golang:1.15 as BUILD

WORKDIR /app

COPY . .

ENTRYPOINT ["go", "test", "-v", "./...", "-coverprofile", "cover.out"]

We can setup a docker-compose.yaml file like the following one so it’s easier to spin up all needed containers at once:

version: '3'

services:
  testsuite:
    build:
      context: .
      dockerfile: build/ci/Dockerfile.test
    depends_on:
      - db
    volumes:
      - .:/app

  db:
    image: mysql
  // ... Add all the dependencies like DB, external APIs..., and add them as depends_on in the testsuite container

Then just executing docker-compose up will see the tests results after all dependencies are running.