kshitij
kshitij

Reputation: 3

Cant run the test class "No tests found with test runner 'Junit5'"

I've created a simple Maven java application in which I am trying to run the Test case.

when doing run as JunitTestCase it gives a popup window stating that "No tests found with test runner 'JUnit5'".

and on console:

Java.lang.NoClassDefFoundError: org/junit/platform/engine/TestEngine
>   at
> org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:35)
>   at
> org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:87)
>   at
> org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:67)
>   at
> org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:34)
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)   at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>   at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
>   at java.lang.Class.newInstance(Class.java:442)  at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:371)
>   at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:366)
>   at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:310)
>   at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:225)
>   at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
> Caused by: java.lang.ClassNotFoundException:
> org.junit.platform.engine.TestEngine  at
> java.net.URLClassLoader.findClass(URLClassLoader.java:382)    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:418)     at
> sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)     at
> java.lang.ClassLoader.loadClass(ClassLoader.java:351)     ... 14 more

my pom.xml has :

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

as well as using: org.junit.jupiter.api.Test

PS:- I am already using JUnit5 annotations. and with "Run as maven-test" zero tests were run is coming.

Upvotes: 0

Views: 1118

Answers (1)

Kathrin Geilmann
Kathrin Geilmann

Reputation: 226

You only depend on the api, giving you e.g. the annotations, but you are missing the engine to execute your tests. Either add junit-jupiter-engine as dependency or switch to the convenience dependency junit-jupiter.

Look at the maven starter sample (https://github.com/junit-team/junit5-samples/tree/r5.7.1/junit5-jupiter-starter-maven), on how to get a minimal functional pom.xml for junit5.

Upvotes: 1

Related Questions