【发布时间】:2017-10-11 20:40:30
【问题描述】:
当我创建 JUnit 测试时:
@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
public final class MyIT {
@Test
public void test() {
... do some tests...
}
}
并运行测试它会导致 SpringBoot 应用程序启动 2 次,第二次将执行测试。
当我删除 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) 时,它会正确启动应用程序一次。
如何在测试中禁用 Spring Boot 应用程序的第一次毫无意义的启动?
【问题讨论】:
-
你真的需要在课堂上使用它吗? :)
-
我需要在隔离环境中运行每个测试(而不是重复使用其他测试中的一个),所以我认为是的。
标签: java spring spring-boot junit spring-test