0

I am using Cucumber framework for writing my ATDD's. I am getting the below error when trying to run Cucumber test.

[INFO] Running my.package.RunCukesTests
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.146 s <<< FAILURE! - in my.package.RunCukesTests
[ERROR] initializationError(my.package.RunCukesTests)  Time elapsed: 0.005 s  <<< ERROR!
java.lang.NoClassDefFoundError: io/cucumber/stepexpression/TypeRegistry
Caused by: java.lang.ClassNotFoundException: io.cucumber.stepexpression.TypeRegistry

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   RunCukesTests.initializationError » NoClassDefFound io/cucumber/stepexpression...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

Below are the Cucumber dependencies:

<properties>
<cucumber.version>3.0.2</cucumber.version>
</properties>
<dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java8</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

RunCuckesTest.java

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "html:target/test_results/html/TestRunner/cucumber-html-report",
        "json:target/test_results/json/TestRunner-reports.json", "pretty" }, tags = { "" }, features = {
                "src/test/resources/" }, glue = { 
                        "glue/package/steps",
                        "glue/package1/steps" })
public class RunCukesTests {
}

When searching in threads with similar exceptions I see that this might cause because of multiple dependencies or when using different versions mismatch. but here I am using same versions and I am not sure where is the issue when I am using the same versions.

Any help is really appreciated. Thanks in Advance.

Marit
  • 2,399
  • 18
  • 27
ging
  • 117
  • 8

2 Answers2

0

Key Point: We shall not mix info.cukes & io.cucumber dependencies specially their versions! Doing so can cause unpredictable outcome.

Solution: You may prefer below correct set of io.cucumber dependencies and update cucumber v as per your framework need.

 <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.2.6</version>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.2.6</version>
</dependency>
TheSociety
  • 1,936
  • 2
  • 8
  • 20
  • Looks like there is dependency with version 4.2.6 for Pico container. More over i am not mixing the versions. info.cukes has a different version than io.cucumber – ging Jun 10 '19 at 14:20
  • We shall not use info.cukes and io.cucumber dependencies together. This is not advisable. – TheSociety Jun 10 '19 at 14:24
  • I removed the "info.cukes" dependencies. Now i am getting a new Error: java.lang.NoSuchMethodError: cucumber.runtime.model.CucumberFeature.(Lgherkin/ast/GherkinDocument;Ljava/lang/String;Ljava/lang/String;)V Any thoughts on this please? @TheSociety – ging Jun 10 '19 at 14:28
  • Hope picocontainer is there from io. Cucumber – TheSociety Jun 10 '19 at 16:33
0

I have almost same configuration and its working fine for me. Please user below dependency and verify if its any other issue or not.

My pom.xml dependency

       <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>2.4.0</version>
        </dependency>


     <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>2.4.0</version>
            <scope>test</scope>
        </dependency>


      <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
        </dependency>

Now if you are using Cucumber 3 then you have to update the pico container version(2.15) too.

Bhavik Shah
  • 140
  • 4
  • 16
  • Please make sure to use the same version for all Cucumber dependencies, in order to prevent any unexpected behaviour. (In your example, update picocontainer to use the same Cucumber version). Also note that v2.4.0 is already quite old; check the [Cucumber documentation](https://cucumber.io/docs/installation/java/) for dependencies and latest version. – Marit Jun 20 '19 at 15:26