Whenever I run my projects JUnit test (using JUnit 5 with Java 9 and Eclipse Oxygen 1.a) I encounter the problem that eclipse can\'t find any tests.
Using STS 3.9.1 I got the same problem. However, currently I do not require any new JUnit5 features, so I tried to force using an older version. If using maven, you can add following dependencies to your pom.xml:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
This did the trick for me (at least as long as I do not need JUnit5 explicitly).
I got the same problem after creating a new TestCase: Eclipse -> New -> JUnit Test Case. It creates a class without access level modifier. I could solve the problem by just putting a public before the class keyword.
From the start the error message tell you that class is not found : NoClassDefFoundError
that mean the PATH to junit is the problem.
Press right click to project folder and choose Properties OR select project folder and press combination cmd + i.
select from list "Java Build Path".
That is all. Try to run test again.
You are missing JUnit 5 platform launcher with group: 'org.junit.platform', name: 'junit-platform-launcher'
Just add in ur POM:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
</dependency>
I have the same issue with STS 3.9.1. It seems like an Eclipse bug, however, to fix this you can add a test dependency junit-platform-launcher
to your project (https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher)
This is how I did for my project which uses gradle:
dependencies {
// other stuff here
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "5.${junit5MinorVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: "1.${junit5MinorVersion}"
}
gradle.properties file:
junit5MinorVersion=1.0
I believe the same applies if you see this exception while using IntelliJ IDEA.
I fixed the issue by right clicking the test and selecting 'Run Configurations' and changing the "Test runner:" selection to 'JUnit 4' as shown here:
I ran the test again and it worked.