Reputation: 21
package cucumber;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
format={"pretty"},
features= "src/features/"
)
public class cucumberRunner {
}
Using:
Error Trace:
java.lang.NoClassDefFoundError: org/dom4j/Element at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetPublicMethods(Unknown Source) at java.lang.Class.getMethods(Unknown Source) at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40) at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:86) at cucumber.runtime.Runtime.(Runtime.java:91) at cucumber.runtime.Runtime.(Runtime.java:69) at cucumber.runtime.Runtime.(Runtime.java:65) at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:78) at cucumber.api.junit.Cucumber.(Cucumber.java:58) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.lang.ClassNotFoundException: org.dom4j.Element at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 28 more
What could be the problem?
Upvotes: 1
Views: 49668
Reputation: 1
On your testRunner, make sure you import the correct Junit libraries. Once you hover your mouse on the @RunWith(Cucumber.class)
, eclipse will provide you with two options, make sure NOT to select "Add JUnit 4 Library to build path"
.
However, select import 'RunWith'(org.junit.runner)
and import it. This will solve the error.
Upvotes: 0
Reputation: 11
It has something do with the jars.Use this below dependency in your pom.xml file. 1.2.5 works! For other versions, I was getting the same error but when I add this dependency, it worked for me without any errors!
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
Import following lines to your code after adding that dependency in your pom.xml file -import org.junit.runner.RunWith; -import cucumber.api.junit.Cucumber;
Upvotes: 1
Reputation: 1
Try importing the below,
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;
Upvotes: -3
Reputation: 6210
The problem is that your class is located in the package 'cucumber'. Either rename the package or move your step-definitions and other glue-code to a sub-package like 'cucumber.steps' and restrict the lookup of glue-code to this package:
package cucumber;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
format={"pretty"},
features= "src/features/",
glue = "cucumber.steps")
public class cucumberRunner {}
Upvotes: 5