Joshua Davies
Joshua Davies

Reputation: 1081

Running JUnit tests in IntelliJ, getting: java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull

I'm trying to run unit tests in IntelliJ, and I'm getting the stack trace:

Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull([Ljava/lang/Object;Ljava/lang/String;)[Ljava/lang/Object; at org.junit.platform.launcher.core.DefaultLauncher.registerTestExecutionListeners(DefaultLauncher.java:71) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:44) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Googling the error message doesn't help - all of the hits I get back have to do with Gradle dependencies, but I'm using Maven (and I've triple-checked my dependencies). Here is my pom:

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.0.0-M3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.0.0-M3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.0.0-M3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

And what's frustrating is that this does actually work in a different project, so I'm not sure what's gone wrong here.

Upvotes: 0

Views: 3012

Answers (1)

Joshua Davies
Joshua Davies

Reputation: 1081

Never mind, I figured it out - in case anybody else has the same problem: It turned out that my unit test was importing org.junit.Test, rather than org.junit.jupiter.api.Test, but I didn't declare a dependency on junit-vintage in my pom.xml. The solution was to either explicitly declare the correct version of junit-vintage in my pom (4.12.0-M3 in my case), or switch my unit tests over to import org.junit.jupiter.api.Test.

Upvotes: 2

Related Questions