Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sbrannen opened this issue Oct 23, 2023 · 2 comments
Closed
Labels
in: test Issues in the test module status: declined A suggestion or change that we don't feel we should currently apply theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement

Comments

@sbrannen
Copy link
Member

sbrannen commented Oct 23, 2023

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

@sbrannen sbrannen added the type: enhancement A general enhancement label Oct 23, 2023
@sbrannen sbrannen added this to the 6.x Backlog milestone Oct 23, 2023
@sbrannen sbrannen added in: test Issues in the test module theme: aot An issue related to Ahead-of-time processing labels Oct 23, 2023
@sbrannen sbrannen changed the title Considering introducing support to abort tests in AOT runtime for JUnit 4 and TestNG Considering introducing support to abort JUnit 4 and TestNG tests in AOT runtime Oct 23, 2023
@snicoll
Copy link
Member

snicoll commented Nov 1, 2023

AFAIK, @DisabledInAotMode is primarily used in relation to native and there's no support for JUnit 4 (and probably never will be). I am a bit confused about the title that looks like it's under consideration but the issue has been triaged for 6.x.

Unless I've missed something, my vote is to close this. We can reconsider if someone actually has any need for such support.

@sbrannen sbrannen changed the title Considering introducing support to abort JUnit 4 and TestNG tests in AOT runtime Introduce support for aborting JUnit 4 and TestNG tests in AOT runtime Jan 2, 2024
@sbrannen sbrannen modified the milestones: 6.x Backlog, General Backlog Jan 2, 2024
@sbrannen
Copy link
Member Author

sbrannen commented Jan 8, 2024

AFAIK, @DisabledInAotMode is primarily used in relation to native and there's no support for JUnit 4 (and probably never will be).

spring-test has explicit AOT support for JUnit 4 and implicit AOT support for TestNG.

In addition, the GraalVM Native Build Tools (NBT) project has explicit support for JUnit 4, and TestNG is theoretically supported due to the TestNG Engine for the JUnit Platform since NBT supports any JUnit Platform TestEngine.

I am a bit confused about the title that looks like it's under consideration but the issue has been triaged for 6.x.

I've changed the title to avoid the confusion.

Unless I've missed something, my vote is to close this. We can reconsider if someone actually has any need for such support.

I agree. If the community expresses interest in these features we can revisit this topic.

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2024
@sbrannen sbrannen added the status: declined A suggestion or change that we don't feel we should currently apply label Jan 8, 2024
@sbrannen sbrannen removed this from the General Backlog milestone Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module status: declined A suggestion or change that we don't feel we should currently apply theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants