Skip to content

@MethodSource fails to load class with custom ClassLoader arrangement #3279

@chrisr3

Description

@chrisr3

JUnit tests with @MethodSource fail inside an OSGi framework after upgrading from 5.9.2 to 5.9.3.

# Execution Started: testMethodSource(String) - [engine:bnd-bundle-engine]/[bundle:test-junit5-tests;1.0.0.SNAPSHOT]/[sub-engine:junit-jupiter]/[class:org.testing.junit.TestJUnit]/[test-template:testMethodSource(java.lang.String)]
# Execution Finished: testMethodSource(String) - [engine:bnd-bundle-engine]/[bundle:test-junit5-tests;1.0.0.SNAPSHOT]/[sub-engine:junit-jupiter]/[class:org.testing.junit.TestJUnit]/[test-template:testMethodSource(java.lang.String)] - TestExecutionResult [status = FAILED, throwable = org.junit.platform.commons.JUnitException: Could not load class [org.testing.junit.TestJUnit]]
org.junit.platform.commons.JUnitException: Could not load class [org.testing.junit.TestJUnit]
        at org.junit.jupiter.params.provider.MethodArgumentsProvider.lambda$loadRequiredClass$8(MethodArgumentsProvider.java:181)
        at org.junit.platform.commons.function.Try$Failure.getOrThrow(Try.java:335)
        at org.junit.jupiter.params.provider.MethodArgumentsProvider.loadRequiredClass(MethodArgumentsProvider.java:180)
        at org.junit.jupiter.params.provider.MethodArgumentsProvider.findFactoryMethodByFullyQualifiedName(MethodArgumentsProvider.java:117)
        at org.junit.jupiter.params.provider.MethodArgumentsProvider.findFactoryMethod(MethodArgumentsProvider.java:82)
        ...
Caused by: java.lang.ClassNotFoundException: org.testing.junit.TestJUnit
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at org.junit.platform.commons.util.ReflectionUtils.lambda$tryToLoadClass$9(ReflectionUtils.java:831)
        at org.junit.platform.commons.function.Try.lambda$call$0(Try.java:57)
        at org.junit.platform.commons.function.Try.of(Try.java:93)
        ...

Steps to reproduce

Run attached Gradle project:

$ ./gradlew clean build

Context

  • Used versions (Jupiter/Vintage/Platform):
    Jupiter 5.9.3
    Platform 1.9.3
  • Build Tool/IDE:
    Gradle 8.1.1
    Java 11

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions