Overview
While migrating the Spring Framework test suite from JUnit 4 and Hamcrest to JUnit Jupiter and AssertJ, entire projects in Spring's test suite started reporting zero tests after removing the dependency on Hamcrest even though the tests no longer used Hamcrest. Adding Hamcrest back as a test runtime dependency allowed the tests to execute again.
Analysis
Thanks to some investigative work by @marcphilipp, we came to the following conclusion.
The JupiterTestEngine fails with a NoClassDefFoundError if JUnit 4 is on the classpath but Hamcrest is not. The underlying reason is that OpenTest4JAndJUnit4AwareThrowableCollector has a static initialization block that checks if the org.junit.internal.AssumptionViolatedException class can be loaded. However, since AssumptionViolatedException has a direct dependency on org.hamcrest.Matcher, a NoClassDefFoundError is thrown when attempting to load AssumptionViolatedException.
Deliverables
Overview
While migrating the Spring Framework test suite from JUnit 4 and Hamcrest to JUnit Jupiter and AssertJ, entire projects in Spring's test suite started reporting zero tests after removing the dependency on Hamcrest even though the tests no longer used Hamcrest. Adding Hamcrest back as a test runtime dependency allowed the tests to execute again.
Analysis
Thanks to some investigative work by @marcphilipp, we came to the following conclusion.
The
JupiterTestEnginefails with aNoClassDefFoundErrorif JUnit 4 is on the classpath but Hamcrest is not. The underlying reason is thatOpenTest4JAndJUnit4AwareThrowableCollectorhas astaticinitialization block that checks if theorg.junit.internal.AssumptionViolatedExceptionclass can be loaded. However, sinceAssumptionViolatedExceptionhas a direct dependency onorg.hamcrest.Matcher, aNoClassDefFoundErroris thrown when attempting to loadAssumptionViolatedException.Deliverables
OpenTest4JAndJUnit4AwareThrowableCollectorso that a failed attempt to detect the presence ofAssumptionViolatedExceptionin the classpath does not crash the entireJupiterTestEngine.