Skip to content

Introduce support for aborting JUnit 4 and TestNG tests in AOT runtime #31478

Closed as not planned
@sbrannen

Description

@sbrannen

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

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently applytheme: aotAn issue related to Ahead-of-time processingtype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions