question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
Argelbargelcommented, Nov 19, 2015

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 😄

4reactions
awaisabircommented, Nov 6, 2017

@Argelbargel I LOVE YOU. SAVED MY LIFE ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

InitializationError while running Cucumber JUnit Tests
The problem is that your class is located in the package 'cucumber'. Either rename the package or move your step-definitions and other ...
Read more >
How to fix cucumber step does not have matching glue code?
The "glue" Cucumber option specifies the package where the step definition files are located. I don't think you need the runner package.
Read more >
JUnit Test Runner Class - Cucumber - Tools QA
Create a new Class file in the 'cucumberTest' package and name it as 'TestRunner', by right click on the Package and select New...
Read more >
IntelliJ Cucumber support fails after update from ... - YouTrack
Just upgraded to 2017.3, but still not working, error is Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/formatter/Formatter when running a ...
Read more >
Re: [Cucumber] [JVM] Cucumber test is not finding the Step ...
What you should put there is a package name (i.e. com, com.company_name, ... the Cucumber JVM for testing the Web Apps and I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found