Quick Guide on How to Run Containers from Tests
Software Development
Bartlomiej Kuczyński
2022-08-16

Quick Guide on How to Run Containers from Tests

Learn how to run containers form tests in our Java related article where our senior java developer shows all the magic.

I use spring boot in the project to reduce boilerplate.

Testcontainers are independent from Spring Framework and you can use them without that.

I use Testcontainers version 1.17.3, but feel free to use the newest one.Tests with Postgres container.

>@Testcontainers
>class SimpleDbTest {
>
>@Container
>private static Postgres13TC postgres13TC = Postgres13TC.getInstance();

@Testcontainers
class SimpleDbTest {

@Container
private static Postgres13TC postgres13TC = Postgres13TC.getInstance();

>@Slf4j
>public class ContainerInit implements
>ApplicationContextInitializer<ConfigurableApplicationContext> {
>
>public static Postgres13TC postgres13TC;


@Slf4j
public class ContainerInit implements
ApplicationContextInitializer<ConfigurableApplicationContext> {

public static Postgres13TC postgres13TC;

Testcontainers are very easy-to-use tools that help us to create integration tests that use Docker containers. That gives us more flexibility and increases development speed. Proper setup of test configuration reduces the time needed to board new developers. They don't need to set up all dependencies, just run the written tests with selected configuration files.

Meet Java expert

Read more:

The Right Way to Find Top Java Developers

Test Containers – How to Make Tests Easier?

Top Programming Languages for Fintech Companies