Description
Overview
The @DisabledInAotMode
annotation introduced in conjunction with #30834 disables any test class during AOT processing, but it only disables JUnit Jupiter tests during AOT runtime (via a JUnit Jupiter ExecutionCondition
).
If we want to provide similar support for JUnit 4 and TestNG based tests, we would need to take a different approach -- for example, by aborting tests via an exception.
-
JUnit 4 supports
org.junit.AssumptionViolatedException
for this purpose. -
TestNG supports
org.testng.SkipException
for this purpose.
These types of exceptions could be thrown from dedicated TestExecutionListener
implementations or via static utility methods that we could make available to users.
For example, the following works for JUnit 4.
public static void abortInAotMode(Class<?> testClass) {
Assume.assumeFalse("Test class [%s] is not supported in AOT mode".formatted(testClass.getName()),
AotDetector.useGeneratedArtifacts());
}
And the following works for TestNG.
public static void abortInAotMode(Class<?> testClass) {
if (AotDetector.useGeneratedArtifacts()) {
throw new SkipException("Test class [%s] is not supported in AOT mode"
.formatted(testClass.getName()));
}
}
A proof-of-concept implementation has been pushed to the following branch for TestNG based tests: main...sbrannen:TestNG-abort-in-AOT-mode