I am using the test container for integration testing and end-to-end testing of the micronaut application.
Here is the configuration for the test container
@Testcontainers
public abstract class TestContainerFixture {
protected static final GenericContainer mongoDBContainer;
protected static final Map<String, Object> properties;
static {
mongoDBContainer = new GenericContainer(DockerImageName.parse("mongo:4.0.10"))
.withExposedPorts(27017)
.withReuse(true);
mongoDBContainer.start();
properties = Map.of("mongodb.uri",
String.format("mongodb://%s:%s", mongoDBContainer.getContainerIpAddress(), mongoDBContainer.getMappedPort(27017)));
}
protected ApplicationContext applicationContext;
}
A class extending the test container
public class DiscountUpdateListenerTest extends TestContainerFixture {
}
Since I am using .withReuse(true);
to reuse the test container for all the other test class. If I disable the .withReuse(false)
on each class when the integration test is running, the container is created which takes the longer time for the test to execute.
So, to reuse the same container I have used the feature .withReuse(true)
. Since the container remain there for longer period of time. So I want to remove the container on each 1-2 hours