Docker Compose and TestContainers
Explore how to use TestContainers-scala alongside Docker Compose to mock external services for integration testing in Scala. This lesson covers setting up container dependencies, configuring ports, waiting strategies, and writing test suites to validate interactions with LocalStack.
We'll cover the following...
In this lesson, we’ll use TestContainers-scala with a Docker Compose file describing the infrastructural dependencies of our application. The only dependency we’ll need is a Docker container running LocalStack. While a Docker Compose file isn’t necessary, it’s a good way to understand how the approach works.
The Docker Compose file
The first thing we have to do when we want to use TestContainers-scala with a Docker Compose file is write a file listing all our external services. In the following examples, we’ll be using only LocalStack, so our Docker Compose file will only have one service.
The file closely follows the format required by Docker Compose. We specify the version and the list of services. For each one, we can state the Docker image that should be pulled to run the container, a restart policy, and a port mapping. Note how we’re not mapping any container ports to the host (i.e., our workstation). ...