Appearance
Fresh
Testcontainers for Java
Back
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
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
CustomerServicethat 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
Create the project Set up a Java project with Maven and implement a PostgreSQL-backed customer service.
Write tests Write your first integration test using Testcontainers for Java and PostgreSQL.
Run tests Run your Testcontainers-based integration tests and explore next steps.