When 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.:
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
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 :-D
Thank you, this report helped me as I had the same problem.
@Argelbargel I LOVE YOU. SAVED MY LIFE <3
@awaisabir You are right! It saved my life tooo! Skkrrr pop pop!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
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 :-D