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

JUnit Jupiter 5.12 fails to find tests with Maven Surefire #4341

Closed
1 task
cbm64chris opened this issue Feb 25, 2025 · 11 comments
Closed
1 task

JUnit Jupiter 5.12 fails to find tests with Maven Surefire #4341

cbm64chris opened this issue Feb 25, 2025 · 11 comments

Comments

@cbm64chris
Copy link

cbm64chris commented Feb 25, 2025

Upgrading from junit-jupiter-api:5.11.4 and junit-platform-commons:1.11.4 to 5.12.0 and 1.12.0 respectively causes: "TestEngine with ID 'junit-jupiter' failed to discover tests”.

The pom.xml in my project contains;

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>

junit-platform-commons is transitive.

mockito-junit-jupiter:5.15.2 is included which brings in mockito-core at the same version.

I include surefire with 5.12.0 engine.

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <groups>UnitTests</groups>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.junit.jupiter</groupId>
                        <artifactId>junit-jupiter-engine</artifactId>
                        <version>${junit.jupiter.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

UnitTests is a @Tag("UnitTests”) on the classes.

The error is thrown:

TestEngine with ID 'junit-jupiter' failed to discover tests
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:132)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:78)
	at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:99)
	at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:77)
	at org.junit.platform.launcher.core.DelegatingLauncher.discover(DelegatingLauncher.java:42)
	at org.apache.maven.surefire.junitplatform.LazyLauncher.discover(LazyLauncher.java:50)
	at org.apache.maven.surefire.junitplatform.TestPlanScannerFilter.accept(TestPlanScannerFilter.java:52)
	at org.apache.maven.surefire.api.util.DefaultScanResult.applyFilter(DefaultScanResult.java:87)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.scanClasspath(JUnitPlatformProvider.java:142)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:122)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
Caused by: java.lang.NoSuchMethodError: 'org.junit.platform.engine.reporting.OutputDirectoryProvider org.junit.platform.engine.EngineDiscoveryRequest.getOutputDirectoryProvider()'
	at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:67)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)

Adding junit-platform-engine:1.12.0 to the classpath produces the same outcome but a different cause;

Caused by: 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.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
	... 15 more

The project is JDK 11 running maven 3.9.9.

My project runs on Jenkins with a renovate GitHub app pulling in updates for PR. All projects with 5.12.0 fail with the same error.

Steps to reproduce

mvn clean test

Context

  • Used versions (Jupiter/Vintage/Platform): Jupiter
  • Build Tool/IDE: Maven

Deliverables

  • ...
@cbm64chris
Copy link
Author

I included on the classpath which enabled my tests to pass.

<dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <scope>test</scope>
        </dependency>

Copy link

Please assign a milestone to this issue or label it with type: task or type: question.

@github-actions github-actions bot reopened this Feb 25, 2025
Copy link

Please assign a milestone to this issue or label it with type: task or type: question.

@github-actions github-actions bot reopened this Feb 25, 2025
@sormuras sormuras closed this as not planned Won't fix, can't repro, duplicate, stale Feb 25, 2025
Copy link

Please assign a status label to this issue.

@mpkorstanje
Copy link
Contributor

@cbm64chris (any anyone else with the same issue) the recommend solution is to use the junit-bom to align dependency versions as recommended by the user guide. This also works on transitive dependencies.

You also don't have to declare a dependency on junit-jupiter-engine for the Surefire plugin. Adding junit-jupiter as a test scoped dependency is sufficient.

@klassm
Copy link

klassm commented Feb 25, 2025

@mpkorstanje Should this also work for Gradle? I followed the user guide - which specifies to have

    testImplementation 'org.junit.jupiter:junit-jupiter'
    testImplementation(platform("org.junit:junit-bom:5.12.0"))

Unfortunately, afterwards the error persists. 🤷

@swa-chacor
Copy link

had to replace

testImplementation 'org.junit.jupiter:junit-jupiter:5.12.0'

by

testImplementation(platform('org.junit:junit-bom:5.12.0'))
testImplementation('org.junit.jupiter:junit-jupiter')
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

to make this version work

@mpkorstanje
Copy link
Contributor

@marcphilipp for Gradle there is a difference between what JUnit and Gradle documentation recommends.

And only the synthesis of both seems to be working.

The JUnit docs did not catch the requirement to declare the test framework implementation with Gradle 8, while the Gradle docs did not include the use of the BOM.

Copy link

Please assign a milestone to this issue or label it with type: task or type: question.

@github-actions github-actions bot reopened this Feb 25, 2025
@marcphilipp
Copy link
Member

Using the BOM is not necessary for Gradle because the Gradle Module Metadata that is published as part of all JUnit 5 artifacts automatically pulls in the BOM.

Therefore this should work:

testImplementation("org.junit.jupiter:junit-jupiter:5.12.0")
testImplementation("org.junit.platform:junit-platform-launcher")

@marcphilipp
Copy link
Member

I've created #4343 to improve the Gradle section in our User Guide to reflect the requirement introduced in Gradle 8.

@sbrannen sbrannen changed the title Junit Jupiter API 5.12 JUnit Jupiter 5.12 fails to find tests with Maven Surefire Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants