1
votes
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:

  • cucumber-core-1.2.4
  • cucumber-java-1.2.4
  • cucumber-junit-1.2.4
  • junit-4.12
  • Eclipse Mars.1
  • java 8

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?

3

3 Answers

5
votes

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 {}
0
votes

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;

-1
votes

Try importing the below,

import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;