Testcontainers for Go spins up Docker dependencies in tests via a programmatic API and tears them down when tests finish.
Overview
Testcontainers for Go is a Go package aimed at automated integration and smoke tests that need real services in containers. Developers define which containers should run during a test; the library handles creation and cleanup when the test completes.
Documentation is published at golang.testcontainers.org and generated from the project docs tree. A quickstart guide explains adding the dependency to a Go module. Inline documentation and examples are also available on pkg.go.dev.
The wider Testcontainers project supports multiple languages; the Go edition is the Go implementation. Adopters listed in the docs include teams using it for server testing, metrics agents, microservice end-to-end checks, and OpenTelemetry collector integration tests.
The API is straightforward for declaring test-time infrastructure without manual Docker orchestration in each test file.
Key features
- Programmatic container lifecycle in tests
- Automatic cleanup after tests
- Go module dependency
- Documented quickstart flow
- pkg.go.dev examples
- Integration and smoke test focus
- Part of multi-language Testcontainers family
- Used by observability and APM projects
Use cases
- Database integration tests in Go
- Smoke testing microservices
- Collector receiver integration tests
- Ephemeral dependencies in CI
- Local parity with production services