Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Junit Jupiter fails to discover tests

While updating JUnit from 5.11.4 to 5.12.1, my Java program fails to perform tests with the following exception:

Mär 31, 2025 1:34:48 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNUNG: TestEngine with ID 'junit-jupiter' failed to discover tests
org.junit.platform.commons.JUnitException: OutputDirectoryProvider not available; probably due to unaligned versions of the junit-platform-engine and junit-platform-launcher jars on the classpath/module path.
    at org.junit.platform.engine.EngineDiscoveryRequest.getOutputDirectoryProvider(EngineDiscoveryRequest.java:94)
    at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:67)
    at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:168)
    at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:155)
    at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:120)
    at org.apache.maven.surefire.junitplatform.TestPlanScannerFilter.accept(TestPlanScannerFilter.java:56)
    at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:102)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.scanClasspath(JUnitPlatformProvider.java:143)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
    at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)

My pom.xml includes the following dependencies:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.12.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.12.1</version>
    <scope>test</scope>
</dependency>

maven-surefire-plugin and maven-failsafe-plugin are integrated as a plugin with version 2.22.2.

Even creating the dependency tree with Maven, I don't see any conflicts concerning junit-jupiter:

[INFO] +- org.slf4j:slf4j-api:jar:2.0.17:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.3.15:compile
[INFO] |  +- (ch.qos.logback:logback-core:jar:1.3.15:compile - omitted for duplicate)
[INFO] |  \- (org.slf4j:slf4j-api:jar:2.0.7:compile - omitted for conflict with 2.0.17)
[INFO] +- ch.qos.logback:logback-core:jar:1.3.15:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.36:provided
[INFO] +- org.apache.maven.plugins:maven-compiler-plugin:jar:3.14.0:compile
[INFO] |  +- org.apache.maven.shared:maven-shared-utils:jar:3.4.2:compile
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.36:compile - omitted for conflict with 2.0.17)
[INFO] |  |  \- commons-io:commons-io:jar:2.11.0:compile
[INFO] |  +- org.apache.maven.shared:maven-shared-incremental:jar:1.1:compile
[INFO] |  +- org.codehaus.plexus:plexus-java:jar:1.4.0:compile
[INFO] |  |  +- org.ow2.asm:asm:jar:9.7.1:compile
[INFO] |  |  \- com.thoughtworks.qdox:qdox:jar:2.2.0:compile
[INFO] |  +- org.codehaus.plexus:plexus-compiler-api:jar:2.15.0:compile
[INFO] |  |  +- (org.codehaus.plexus:plexus-utils:jar:4.0.0:compile - omitted for conflict with 4.0.1)
[INFO] |  |  \- (org.slf4j:slf4j-api:jar:1.7.36:compile - omitted for conflict with 2.0.17)
[INFO] |  +- org.codehaus.plexus:plexus-compiler-manager:jar:2.15.0:compile
[INFO] |  |  +- (org.codehaus.plexus:plexus-compiler-api:jar:2.15.0:compile - omitted for duplicate)
[INFO] |  |  +- javax.inject:javax.inject:jar:1:compile
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.36:compile - omitted for conflict with 2.0.17)
[INFO] |  |  \- org.codehaus.plexus:plexus-xml:jar:3.0.0:compile
[INFO] |  +- org.codehaus.plexus:plexus-compiler-javac:jar:2.15.0:runtime
[INFO] |  |  +- (org.codehaus.plexus:plexus-utils:jar:4.0.0:runtime - omitted for conflict with 4.0.1)
[INFO] |  |  +- (javax.inject:javax.inject:jar:1:runtime - omitted for duplicate)
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.36:runtime - omitted for conflict with 2.0.17)
[INFO] |  |  \- (org.codehaus.plexus:plexus-compiler-api:jar:2.15.0:runtime - omitted for duplicate)
[INFO] |  \- org.codehaus.plexus:plexus-utils:jar:4.0.1:compile
[INFO] +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile
[INFO] |  \- jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
[INFO] +- javax.activation:activation:jar:1.1:compile
[INFO] +- org.glassfish.jaxb:jaxb-runtime:jar:2.3.9:compile
[INFO] |  +- (jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile - omitted for duplicate)
[INFO] |  +- org.glassfish.jaxb:txw2:jar:2.3.9:compile
[INFO] |  +- com.sun.istack:istack-commons-runtime:jar:3.0.12:compile
[INFO] |  \- com.sun.activation:jakarta.activation:jar:1.2.2:runtime
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.12.1:test
[INFO] |  +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] |  +- org.junit.platform:junit-platform-commons:jar:1.12.1:test
[INFO] |  |  \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] |  \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.12.1:test
[INFO] |  +- org.junit.platform:junit-platform-engine:jar:1.12.1:test
[INFO] |  |  +- (org.opentest4j:opentest4j:jar:1.3.0:test - omitted for duplicate)
[INFO] |  |  +- (org.junit.platform:junit-platform-commons:jar:1.12.1:test - omitted for duplicate)
[INFO] |  |  \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] |  +- (org.junit.jupiter:junit-jupiter-api:jar:5.12.1:test - omitted for duplicate)
[INFO] |  \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] \- org.apache.commons:commons-lang3:jar:3.17.0:compile

Turning back to junit-jupiter 5.11.4, everything works fine. My Java version is currently 1.8.0_302; my Maven version is 3.9.9.

Furthermore, based on 5.11.4, all test classes are collected, so I think the naming convention of class names should be correct.

Can anyone give me any advice, how to get rid of this problem? I know, there are many similar issues with this message - but I don't see any conflict here.

like image 218
Alex Avatar asked Nov 20 '25 06:11

Alex


1 Answers

testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.12.2'

for gradle I had to add the line above to make it work. I have these three lines now:

testImplementation 'org.junit.jupiter:junit-jupiter:5.12.2'
testRuntimeOnly 'org.junit.platform:junit-platform-engine:1.12.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.12.2'
like image 169
bmaj Avatar answered Nov 22 '25 21:11

bmaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!