简体   繁体   中英

Cucumber framework throwing an error while running tests

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.

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM