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 complete
20 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
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 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.