Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Junit-Runner for Cucumber throws ClassNotFoundException if package name is 'cucumber' and no package for glue-code is specified #934

Closed
Argelbargel opened this issue Nov 19, 2015 · 5 comments

Comments

@Argelbargel
Copy link

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.:

  • 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

@Argelbargel
Copy link
Author

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

@Argelbargel Argelbargel changed the title Junit-Runner for Cucumber throws ClassNotFoundException if no package for glue-code is specified Junit-Runner for Cucumber throws ClassNotFoundException if package name is 'cucumber' and no package for glue-code is specified Nov 19, 2015
@mlvandijk
Copy link
Member

Thank you, this report helped me as I had the same problem.

@awaisabir
Copy link

@Argelbargel I LOVE YOU. SAVED MY LIFE <3

@theoJA
Copy link

theoJA commented Nov 6, 2017

@awaisabir You are right! It saved my life tooo! Skkrrr pop pop!

@lock
Copy link

lock bot commented Nov 6, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants