ksl
ksl

Reputation: 4699

Error when running JUnit 5 tests in IntelliJ but not on the command line

The following error is reported when I attempt to run a simple JUnit 5 test in IntelliJ:

Feb 08, 2019 3:37:39 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable 
WARNING: TestEngine with ID 'junit-vintage' failed to discover tests 
java.lang.NoSuchMethodError: org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List; 
at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.filterAndConvertToTestClassRequests(JUnit4DiscoveryRequestResolver.java:79)
at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.resolve(JUnit4DiscoveryRequestResolver.java:48)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:64) 
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:177) 
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:164) 
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:120) 
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:49) 
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) 
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) 
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V 
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:61) 
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) 
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) 
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Process finished with exit code 1

This is my pom:

<properties> 
    <java.version>1.8</java.version> 
    <junit.jupiter.version>5.3.2</junit.jupiter.version> 
</properties>

</dependencies> 
    <dependency> 
        <groupId>org.junit.jupiter</groupId> 
        <artifactId>junit-jupiter-api</artifactId> 
        <version>${junit.jupiter.version}</version> 
        <scope>test</scope> 
    </dependency> 
    <dependency> 
        <groupId>org.junit.jupiter</groupId> 
        <artifactId>junit-jupiter-params</artifactId> 
        <version>${junit.jupiter.version}</version> 
        <scope>test</scope> 
    </dependency>

    <!-- Only needed to run tests in a version of IntelliJ IDEA that bundles older versions --> 
    <dependency> 
        <groupId>org.junit.jupiter</groupId> 
        <artifactId>junit-jupiter-engine</artifactId> 
        <version>${junit.jupiter.version}</version> 
        <scope>test</scope> 
    </dependency> 
    <dependency> 
        <groupId>org.junit.platform</groupId> 
        <artifactId>junit-platform-launcher</artifactId> 
        <version>1.4.0</version> 
        <scope>test</scope> 
    </dependency> 
</dependencies>

<build> 
    <plugins> 
        <!-- JUnit 5 requires Surefire version 2.22.1 or higher --> 
        <plugin> 
            <artifactId>maven-surefire-plugin</artifactId> 
            <version>2.22.1</version> 
        </plugin> 
    </plugins> 
</build>

I am using Intellij v2017.1.2.

When I run the test from the command line there are no errors reported.

I've seen various posts reporting similar problems for different versions of IntelliJ but the suggested solutions don't help.

Upvotes: 5

Views: 10450

Answers (1)

Roland Weisleder
Roland Weisleder

Reputation: 10501

The JUnit User Guide suggests to use 2017.3 or newer.

IntelliJ IDEA releases prior to IDEA 2017.3 bundle specific versions of JUnit 5. Thus, if you want to use a newer version of JUnit Jupiter, execution of tests within the IDE might fail due to version conflicts.

Upvotes: 3

Related Questions