Programmatically Creating Containers

Learn how to use TestContainers-scala and write your own container definitions.

In this lesson, we’re going to take a look at a different approach to using TestContainers-scala: programmatically defining containers. This option gives us maximum flexibility, letting us customize every aspect of the Docker containers we’ll be using in our tests. This is our preferred approach when the built-in modules don’t suit our needs. It’s also the way to go when you want to use your own Docker images (for example, additional internal applications needed by your code).

Defining a container

When you decide to create your own container definition, the first step is to model it. Since we’re now writing our own class, it can contain any helper methods we need to make our tests more declarative.

Get hands-on with 1200+ tech skills courses.