Integration testing using Testcontainers
Testcontainers
is a Java library that elegantly marries the world of testing with Docker virtualization. Using the Testcontainers
library, we can set up, instantiate, and inject any Docker container into the testing code. This approach opens up many avenues for performing integration testing. In the test suite or test method setup, we can boot up a Dockerized database, Kafka or email server or any integrating app, perform the integration tests, and destroy the Dockerized app in the cleanup. With this pattern, we are up close to the production environment while not impacting the environment with any after-testing side effects.
To learn how we can use the Testcontainers
library, we will experiment on the pet-clinic-reviews microservice that integrates with MongoDB. In the next section, we will begin setting up Testcontainers
in the Micronaut application.
Setting up the Testcontainers in the Micronaut application
To use Testcontainers...