xxxxxxxxxx
@Testcontainers
class TestcontainersNestedRestartedContainerTests {
@Container
private final GenericContainer<?> topLevelContainer = new GenericContainer<>(JUnitJupiterTestImages.HTTPD_IMAGE)
.withExposedPorts(80);
⋯
@Test
void top_level_container_should_be_running() {
assertThat(topLevelContainer.isRunning()).isTrue();
⋯
}
@Nested
class NestedTestCase {
@Container
private final GenericContainer<?> nestedContainer = new GenericContainer<>(JUnitJupiterTestImages.HTTPD_IMAGE)
.withExposedPorts(80);
@Test
void both_containers_should_be_running() {
// top level container is restarted for nested methods
assertThat(topLevelContainer.isRunning()).isTrue();
// nested containers are only available inside their nested class
assertThat(nestedContainer.isRunning()).isTrue();
⋯
}
⋯
}
}
xxxxxxxxxx
@Testcontainers
class TestcontainersNestedRestartedContainerTests {
@Container
private final GenericContainer<?> topLevelContainer = new GenericContainer<>(JUnitJupiterTestImages.HTTPD_IMAGE)
.withExposedPorts(80);
⋯
@Test
void top_level_container_should_be_running() {
assertThat(topLevelContainer.isRunning()).isTrue();
⋯
}
@Nested
class NestedTestCase {
@Container
private final GenericContainer<?> nestedContainer = new GenericContainer<>(JUnitJupiterTestImages.HTTPD_IMAGE)
.withExposedPorts(80);
@Test
void both_containers_should_be_running() {
// top level container is restarted for nested methods
assertThat(topLevelContainer.isRunning()).isTrue();
// nested containers are only available inside their nested class
assertThat(nestedContainer.isRunning()).isTrue();
⋯
}
⋯
}
}