Skip to content
Fresh

Testcontainers for Java

Back

Guides

Getting started with Testcontainers for Java

Learn how to create a Java application and test database interactions using Testcontainers for Java with a real PostgreSQL instance.

Java Testing with Docker

20 minutes

1

Create the project

2

Write tests

3

Run tests

« Back to all guides

Getting started with Testcontainers for Java

Table of contents


Learn how to create a Java application and test database interactions using Testcontainers for Java with a real PostgreSQL instance.

Time to complete20 minutes

In this guide, you will learn how to:

  • Create a Java project with Maven
  • Implement a CustomerService that manages customer records in PostgreSQL
  • Write integration tests using Testcontainers with a real Postgres database
  • Run the tests and verify everything works

Prerequisites

  • Java 17+
  • Maven or Gradle
  • A Docker environment supported by Testcontainers

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 Java project with Maven and implement a PostgreSQL-backed customer service.

  2. Write tests Write your first integration test using Testcontainers for Java and PostgreSQL.

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