Share feedback
Answers are generated based on the documentation.

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

Note

If you're new to Testcontainers, visit the Testcontainers overview to learn more about Testcontainers and the benefits of using it.

Modules

  1. Create the project

    Set up a Go project with a PostgreSQL-backed repository.

  2. Write tests

    Write your first integration test using testcontainers-go and PostgreSQL.

  3. Test suites

    Share a single Postgres container across multiple tests using testify suites.

  4. Run tests

    Run your Testcontainers-based integration tests and explore next steps.