Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/junit-platform-native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ tasks.named('test') {
delete { delete testIdsDir.get().asFile }
}
useJUnitPlatform() {
systemProperty('junit.jupiter.extensions.autodetection.enabled', true)
systemProperty('junit.platform.listeners.uid.tracking.enabled', true)
systemProperty('junit.platform.listeners.uid.tracking.output.dir', "${testIdsDir.get().asFile.absolutePath}/test_ids")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ abstract class NativeTestArgumentProvider implements CommandLineArgumentProvider
"--no-fallback",
"--features=org.graalvm.junit.platform.JUnitPlatformFeature",
"-o", "native-image-tests",
"-Djunit.jupiter.extensions.autodetection.enabled=true",
"-Djunit.platform.listeners.uid.tracking.output.dir=${testIdsDir.get().asFile.absolutePath}"
]

Expand Down Expand Up @@ -159,5 +160,8 @@ tasks.register("nativeTest", Exec) {
dependsOn nativeTestCompile
workingDir = "${buildDir}"
executable = "${buildDir}/native-image-tests"
args = ["-Djunit.platform.listeners.uid.tracking.output.dir=${testIdsDir.get().asFile.absolutePath}"]
args = [
"-Djunit.jupiter.extensions.autodetection.enabled=true",
"-Djunit.platform.listeners.uid.tracking.output.dir=${testIdsDir.get().asFile.absolutePath}"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.junit.jupiter.api.condition.DisabledIf;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.params.aggregator.AggregateWith;
import org.junit.jupiter.params.converter.ConvertWith;
import org.junit.jupiter.params.provider.ArgumentsSource;
Expand All @@ -61,17 +62,20 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

import static org.graalvm.junit.platform.JUnitPlatformFeatureUtils.debug;

public class JupiterConfigProvider extends PluginConfigProvider {
private static final String EXTENSIONS_AUTODETECTION_ENABLED_PROPERTY_NAME = "junit.jupiter.extensions.autodetection.enabled";

@Override
public void onLoad() {
/* Provide support for Timeout annotation */
JUnitPlatformFeatureUtils.registerAllClassMembersForReflection(Utils.toClasses(
"org.junit.jupiter.engine.extension.TimeoutExtension$ExecutorResource",
"org.junit.jupiter.engine.extension.TimeoutInvocationFactory$SingleThreadExecutorResource"));
registerAutoDetectedExtensionsForReflection();
}

@Override
Expand Down Expand Up @@ -155,6 +159,23 @@ private static Class<?>[] handleMethodReference(String... methodNames) {
return classList.toArray(new Class<?>[0]);
}

private void registerAutoDetectedExtensionsForReflection() {
try {
if (Boolean.getBoolean(EXTENSIONS_AUTODETECTION_ENABLED_PROPERTY_NAME)) {
ServiceLoader.load(Extension.class, applicationClassLoader)
.stream()
.map(ServiceLoader.Provider::type)
.forEach(extensionType -> {
// Service-registered Jupiter extensions need runtime reflection metadata in native tests. §root/FS-native-tests.2.
debug("Registering auto-detected Jupiter extension for reflection: %s", extensionType.getName());
JUnitPlatformFeatureUtils.registerAllClassMembersForReflection(extensionType);
});
}
} catch (NoClassDefFoundError e) {
debug("Cannot register auto-detected Jupiter extensions. Please verify that you have dependency that includes 'org.junit.jupiter.api' if you want to use these extensions.");
}
}

public static void handleEnumSource(Method method, EnumSource source) {
JUnitPlatformFeatureUtils.registerAllClassMembersForReflection(source.value());
if (method.getParameterCount() > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2026, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.graalvm.junit.jupiter;

import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

public class AutodetectedExtension implements BeforeEachCallback, BeforeTestExecutionCallback {

@Override
public void beforeEach(ExtensionContext context) {
System.clearProperty(AutodetectedExtensionTests.EXTENSION_PROPERTY);
}

@Override
public void beforeTestExecution(ExtensionContext context) {
System.setProperty(AutodetectedExtensionTests.EXTENSION_PROPERTY, "true");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2026, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.graalvm.junit.jupiter;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class AutodetectedExtensionTests {
static final String EXTENSION_PROPERTY = "org.graalvm.junit.jupiter.AutodetectedExtension.invoked";

@Test
void appliesServiceRegisteredExtension() {
// Verifies native-test support for Jupiter service-registered extensions. §root/FS-native-tests.2.
Assertions.assertEquals("true", System.getProperty(EXTENSION_PROPERTY));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.graalvm.junit.jupiter.AutodetectedExtension
8 changes: 5 additions & 3 deletions docs/spec/functional/native-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ following must happen during image build:
- Provider classes for JUnit Platform, Jupiter, and Vintage must contribute their Native Image
metadata when the corresponding engine is on the test classpath. New providers may be added
when the repository supports new JUnit Platform behavior.
- When Jupiter extension autodetection is enabled, service-registered
`org.junit.jupiter.api.extension.Extension` providers must be available to the native test image.

The repository's native-test fixtures cover nested tests, method sources, CSV sources, enum
sources, converters, aggregators, class ordering, and display-name generation. The shared launcher
and feature must preserve JUnit Platform semantics for any scenario the repository's fixtures
exercise.
sources, converters, aggregators, class ordering, display-name generation, and service-registered
Jupiter extensions. The shared launcher and feature must preserve JUnit Platform semantics for
any scenario the repository's fixtures exercise.

## 3. Native launcher and feature

Expand Down
Loading