The next level — Testcontainers using SpringBoot and CockroachDB images

Test overview

1. Why?

From Testcontainers GitHub repo, Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

2. Who is using it?

Spotify, Google, Instana, Zalando, Oracle, and others

3. Alternatives

  • Arquillian
  • Docker compose
  • Kubernetes
  • Helm
  • Rancher

4. Requirement

As a developer I want to run my IT without an in-memory database or Mock, using my recent docker images

5. Hands-on

Great, we talked a lot about it but “Show me the money”. Let’s analyze first the application architecture and then add the Testcontainers to meet our requirements.

5.1. AS-IS

If you’re following the previous project state, the project should be like the project below.

Project screen

5.2. TO-BE

And to meet the requirement some classes, configuration files, and dependencies should be added, let’s do this 💪.

Project overview with Testcontainers + SpringBoot + CockroachDB

5.2.1. Package layer

In the package layer, there are 4 classes and 1 package, the example package could be ignored, this package was created for this article.

ApplicationConfigurationReader class — getters omitted
Zero2HeroInfraSupport class
GenreContainerIT class
GenreContainerIT test
MovieContainerIT class

5.2.2. Resources folder

5.2.3. Project root build.gradle

partial build.gradle

6. Tech stack

  • Java 11
  • Testcontainers CockroachDB 1.17.2
  • Gradle 8
  • JUnit 5
  • Docker



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Luiz Gustavo De O. Costa

Luiz Gustavo De O. Costa

Hey friend!! I’m Luiz Gustavo, a Java developer and I’m here to learn and write about Java, tests and good practices