Support autodetected Jupiter extensions in native tests#919
Open
jormundur00 wants to merge 1 commit into
Open
Conversation
4d4180b to
49e0c3e
Compare
49e0c3e to
6bdd60d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #652
What changed
This PR adds support for JUnit Jupiter extensions discovered through
META-INF/serviceswhenjunit.jupiter.extensions.autodetection.enabled=trueis used in native tests.Before this change, service-registered Jupiter extensions could be present and autodetection could be enabled, but the extension classes were not registered for native-image reflection.
After this change, service-loaded Jupiter extensions are registered for reflection when autodetection is enabled, so they can participate in native test execution.
Why
Users expect Jupiter extension autodetection to work the same way in native tests as it does in the JVM test path when the required service registration is present.
Example
Before:
A Jupiter extension registered through
META-INF/services/org.junit.jupiter.api.extension.Extensioncould be discovered conceptually, but the native test path would still fail to apply it because the extension class was not prepared for native-image reflection.After:
The same service-registered extension is reflected into the image and runs successfully when autodetection is enabled.
Implementation summary
org.junit.jupiter.api.extension.Extensionprovider classes for reflection fromJupiterConfigProviderwhen Jupiter extension autodetection is enabled.ServiceLoader.Provider::typeso user extensions are not instantiated during image setup.Validation
grund checkJAVA_HOME=/home/jovan/.sdkman/candidates/java/17.0.12-graal ./gradlew --no-daemon :junit-platform-native:checkstyleMain :junit-platform-native:checkstyleTestJAVA_HOME=/home/jovan/.sdkman/candidates/java/17.0.12-graal ./gradlew --no-daemon :junit-platform-native:testJAVA_HOME=/home/jovan/.sdkman/candidates/java/17.0.12-graal GRAALVM_HOME=/home/jovan/.sdkman/candidates/java/17.0.12-graal ./gradlew --no-daemon :junit-platform-native:nativeTestgit diff --check