We recently migrated our test framework to JUnit5 and are having some issues using @Disabled
(und ExecutionCondition
s) in tests which are using @SpringJUnitConfig
:
In Junit4 @Ignore
disabled the test execution without question and without executing anything. With Junit5 and @Disabled
, the system now creates the spring context before realizing that the test should not be executed. In our case this leads to disabled tests failing, because some of them are disabled because the context cannot be created under some circumstances.
Is it possible to disable a test (class) in JUnit5 in a way that no spring context is created for this test?
Minimal example:
@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 {
}
}
This is a bug in JUnit Jupiter that only occurs when using the PER_CLASS
test instance lifecycle mode.
I have raised the following issue in the JUnit 5 issue tracker to address this issue. https://github.com/junit-team/junit5/issues/1103
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With