【发布时间】:2018-06-27 21:04:50
【问题描述】:
我有这个用于 IT 测试的抽象类:
@RunWith(SpringRunner.class)
@Import(DbUnitConfig.class)
@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@DbUnitConfiguration(dataSetLoader = DbUnitDataSetLoader.class)
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class,
DbUnitTestExecutionListener.class
})
public abstract class AbstractIT {
@ClassRule
public static final DockerComposeContainer postgres =
new DockerComposeContainer(new File("src/test/resources/docker-compose-postgres.yml"))
.withExposedService("cars-user-postgres-it", 5432);
}
当我只启动 IT 测试类的一个实例时,它可以正常工作。
但是当我启动多个测试类时,第一个会完成,另一个会因为关闭 postgres 而失败
这是来自 Container 的日志:
Stopping 1ykxuc_postgres-it_1 ...
Stopping 1ykxucpostgres-it_1 ... done
Removing 1ykxuc_postgres-it_1 ...
Removing 1ykxuc_cars-user-postgres-it_1 ... done
Removing network 1ykxuc_default
如何告诉 TestContainers 在一个类执行后不要停止容器,而是在所有容器都完成后停止?
【问题讨论】:
标签: java testcontainers