Skip to content

Bunch of sample projects that showcase how to use Testcontainers with Spring Boot, JUnit 5, Kotest together with PostgreSQL or Kafka. Finally, this repo shows not only how to test with Testcontainers, but also how to run your application locally

License

wpanas/testcontainers-examples

Repository files navigation

Testcontainers Examples

This repository contains sample projects that use Testcontainers with different technologies. I hope it will help you use it in your own projects.

All samples are build with Kotlin, Gradle & JUnit 5.

👉 If you use JDK 17+ & Spring Boot 3.1+ go straight to the simplest project. Other projects use older Spring Boot 2.7 to show how to use Testcontainers without all great advancements that since were made. As for now, 2.7 is still commercially supported until 2025-08-24. I encourage you to update Spring Boot according to the official support timeline to have the best experience with Testcontainers and what not.

Current tests status is:

wpanas

Sample projects

How to use it?

Run all tests

./gradlew check 

Run kafka module tests

./gradlew kafka:check

Run postgres module tests

./gradlew local-db:check 

Run spring6-junit5 tests

./gradlew spring6-junit5:check 

Run spring-junit5 tests

./gradlew spring-junit5:check

Run spring-kotest tests

./gradlew spring-kotest:check

How to run local development?

💥 NEW! To run locally application with a Postgresql container configured by Testcontainers & Spring Boot 3.1+.

./gradlew spring6-junit5:bootTestRun

To run locally application with a Kafka container configured by Testcontainers.

./gradlew kafka:bootLocalRun

To run locally application with a Postgresql container configured by Testcontainers.

./gradlew local-db:bootLocalRun

Troubleshooting

ContainerFetchException

If you got ContainerFetchException because of failing Docker environment should have more than 2GB free disk space, increase available disc space in Docker for Mac. See more.

About

Bunch of sample projects that showcase how to use Testcontainers with Spring Boot, JUnit 5, Kotest together with PostgreSQL or Kafka. Finally, this repo shows not only how to test with Testcontainers, but also how to run your application locally

Topics

Resources

License

Stars

Watchers

Forks

Languages