Getting started with Testcontainers for Go
Table of contents
Learn how to create a Go application and test database interactions
using Testcontainers for Go with a real PostgreSQL instance.
Time to complete
20 minutes
In this guide, you will learn how to:
- Create a Go application with modules support
- Implement a Repository to manage customer data in a PostgreSQL database using the pgx driver
- Write integration tests using testcontainers-go
- Reuse containers across multiple tests using test suites
Prerequisites
- Go 1.25+
- Your preferred IDE (VS Code, GoLand)
- A Docker environment supported by Testcontainers. For details, see the testcontainers-go system requirements.
NoteIf you're new to Testcontainers, visit the Testcontainers overview to learn more about Testcontainers and the benefits of using it.
Modules
- Create the project
Set up a Go project with a PostgreSQL-backed repository.
- Write tests
Write your first integration test using testcontainers-go and PostgreSQL.
- Test suites
Share a single Postgres container across multiple tests using testify suites.
- Run tests
Run your Testcontainers-based integration tests and explore next steps.