Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "java.lang.NoClassDefFoundError: org/junit/platform/engine/DiscoverySelector" trying to run Serenity JBheave

Created a new generic Serenity BDD JBehave framework with Maven ( via command line).

Imported the project into Intelli J but when i try to run the "AcceptanceTestSuite" I get an error saying "No Tests are Found" and the following errorException in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/engine/DiscoverySelector

I've tried re importing the project but that doesn't solve the problem.

Here is the full error log:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/engine/DiscoverySelector
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetPublicMethods(Class.java:2902)
    at java.lang.Class.getMethods(Class.java:1615)
    at org.jbehave.core.steps.AbstractStepsFactory.hasAnnotatedMethods(AbstractStepsFactory.java:70)
    at net.serenitybdd.jbehave.SerenityStepFactory.getCandidateClasses(SerenityStepFactory.java:61)
    at net.serenitybdd.jbehave.SerenityStepFactory.stepsTypes(SerenityStepFactory.java:48)
    at org.jbehave.core.steps.AbstractStepsFactory.createCandidateSteps(AbstractStepsFactory.java:34)
    at net.serenitybdd.jbehave.SerenityStepFactory.createCandidateSteps(SerenityStepFactory.java:42)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.buildCandidateSteps(SerenityReportingRunner.java:294)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.createCandidateStepsWith(SerenityReportingRunner.java:249)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.createCandidateStepsWithNoMonitor(SerenityReportingRunner.java:257)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.getCandidateSteps(SerenityReportingRunner.java:240)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.buildDescriptionFromStories(SerenityReportingRunner.java:313)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.getDescriptions(SerenityReportingRunner.java:84)
    at net.serenitybdd.jbehave.runners.SerenityReportingRunner.getDescription(SerenityReportingRunner.java:168)
    at com.intellij.junit4.JUnit4IdeaTestRunner.getDescription(JUnit4IdeaTestRunner.java:78)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.DiscoverySelector
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 21 more
like image 585
Timhua Avatar asked Jul 12 '18 14:07

Timhua


3 Answers

Add dependency to pom.xml:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-engine</artifactId>
    <version>1.2.0</version>
</dependency>
like image 100
VaL Avatar answered Oct 08 '22 20:10

VaL


Without using maven, dependencies of Junit 5 are:

enter image description here

junit-jupiter-api

junit-jupiter-engine

junit-platform-engine

junit-platform-commons

junit-vintage-engine (optional)

They can be found: https://junit.org/junit5/

like image 30
An_Bk Avatar answered Oct 08 '22 20:10

An_Bk


In my case we are using gradle, somehow i could not able to solve it, i have added jars manually in eclipse now its working. In Eclipse project → build path → config build path -> libraries → add all libraries related to "jupiterEnginer5.5". Here are all jars for "jupiterEnginer5.5" : opentest4j-1.2.0.jar junit-platform-engine-1.7.0-M1.jar junit-platform-commons-1.7.0-M1.jar junit-jupiter-engine-5.7.0-M1.jar junit-jupiter-api-5.7.0-M1.jar apiguardian-api-1.1.0.jar

like image 27
Chandra Avatar answered Oct 08 '22 20:10

Chandra