Meet TestContainers

Learn how to integrate TestContainers into a Scala project.

Mocking dependencies

When writing integration tests, we sometimes need to mock applicative or infrastructural dependencies.

  • Applicative dependencies, in this context, are every other application our program interacts with in the real world. For example, if we’re developing a microservice architecture, our application will likely have to interact with other microservices. In this case, our integration tests could mock them.

  • Infrastructural dependencies, in this context, are file storage systems (such as AWS S3), databases, and messaging systems. While there are in-memory implementations of most of these services (for example, we can use in-memory implementation of database management systems), the ability to test against the same database we’ll use in production is of real value.

When it comes to mocking applicative or infrastructural dependencies, we can leverage the flexibility of Docker containers. Docker allows us to package and run applications in a loosely isolated environment called a container. Containers are very lightweight, and we can run many of them on the same machine, or host. They contain everything needed to run the application they ship, so when running containers, we don’t have to rely on what’s installed on the host.

Get hands-on with 1200+ tech skills courses.