我们最近将我们的测试框架迁移到了 JUnit5,并且在使用@Disabled(und ExecutionConditions) 的测试中遇到了一些问题@SpringJUnitConfig:在 Junit4 中@Ignore,毫无疑问地禁用了测试执行,并且没有执行任何操作。使用 Junit5 和@Disabled,系统现在在意识到不应执行测试之前创建 spring 上下文。在我们的例子中,这会导致禁用测试失败,因为其中一些被禁用,因为在某些情况下无法创建上下文。
是否可以以不为此测试创建 spring 上下文的方式禁用 JUnit5 中的测试(类)?
最小的例子:
@TestInstance(Lifecycle.PER_CLASS)
@RunWith(JUnitPlatform.class) // To support tests running in eclipse
@SpringJUnitConfig(classes = {BaseTestSpringTest.TestConfiguration.class})
@Disabled
public class BaseTestSpringTest {
@Configuration
@ComponentScan(basePackages = { "my.package" })
public class TestConfiguration {
}
@Component
public class TestClass {
@PostConstruct
public void fail() {
throw new IllegalStateException();
}
}
@Autowired
protected TestClass test;
@Test
public void test() throws Exception {
}
}
Run Code Online (Sandbox Code Playgroud)
这是 JUnit Jupiter 中的一个错误,仅在使用PER_CLASS测试实例生命周期模式时才会发生。
我在 JUnit 5 问题跟踪器中提出了以下问题来解决此问题。https://github.com/junit-team/junit5/issues/1103
| 归档时间: |
|
| 查看次数: |
1078 次 |
| 最近记录: |