Junit-Runner for Cucumber throws ClassNotFoundException if package name is 'cucumber' and no package for glue-code is specified
See original GitHub issueWhen running cucumber-JVM with its JUnit-Runner using gradle i’m getting a ClassNotFoundException/NoClassDefFoundError if the package containing the class annotated with @RunWith(Cucumber.class)
is named ‘cucumber’ and the package is not excluded (e.g. the glue path is set to another package using @CucumberOptions(glue=package)
.
If RunCucumberTest is in a folder/package /src/test/java/cucumber/RunCucumberTest.java
and the glue-code/step-definition at src/test/java/cucumber/steps
, then the following class produces a ClassNotFoundException:
package cucumber;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
public class RunCucumberTest {}
Stacktrace:
java.lang.NoClassDefFoundError: nu/xom/ParsingException
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 cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40)
at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:86)
at cucumber.runtime.Runtime.<init>(Runtime.java:91)
at cucumber.runtime.Runtime.<init>(Runtime.java:69)
at cucumber.runtime.Runtime.<init>(Runtime.java:65)
at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:78)
at cucumber.api.junit.Cucumber.<init>(Cucumber.java:58)
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:422)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
...
The exception is thrown for different classes when running the tests repeatedly, e.g.:
- nu.xom.ParsingException
- org.dom4j.Element
- org.xmlpull.v1.XmlPullParserException
- net.sf.cglib.proxy.CallbackFilter
When I change the package where glue-code is searched, it works:
package cucumber;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(glue = "cucumber.steps")
public class RunCucumberTest {}
The gradle-project can be found at https://github.com/Argelbargel/cucumber-jvm-junit-classnotfoundexecption
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Silly me! The problem is of course, that the package-name for my test-runner-class is the same as cucumber itself. Been staring at this the whole afternoon and only realized it after creating the issue-report 😄
@Argelbargel I LOVE YOU. SAVED MY LIFE ❤️