NoClassDefFoundError:尝试升级到黄瓜4时,cumcum / api / DataTable

时间:2018-11-19 11:53:11

标签: java cucumber

我正在尝试将测试升级到Cucumber4。我正在使用testNG和Maven。

我已经更新了以下依赖项版本:

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>${version.cucumber}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-guice</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>${version.cucumber}</version>
        </dependency>

但是尝试运行测试时,我仍然收到错误消息“ java.lang.NoClassDefFoundError:cumcum / api / DataTable”。

这是我的跑步者:

import cucumber.api.CucumberOptions;
import cucumber.api.*;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.testng.annotations.DataProvider;

@CucumberOptions(plugin = {"XXXX"},
    features = "src/test/resources/features",
    glue={"XXXXX"},
    tags = {"@XXXXX"})

public class Cucumber4Runner extends AbstractTestNGCucumberTests {

    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }

}

我试图确保所有版本的依赖项都能匹配,但仍在努力!

1 个答案:

答案 0 :(得分:3)

很可能您尚未对齐导入语句(可能需要其他更改)。

CHANGELOG.md

  

3.0.0   ...   [Core]用 io.cucumber.datatable.DataTable 替换DataTable(#1248 M.P. Korstanje,BjörnRasmusson,Marit van Dijk)

根据您的异常消息,您的代码正在寻找 cucumber.api.DataTable

编辑,可能还会有一个短暂的依赖关系,从您的其他依赖关系到较旧的黄瓜版本。

仅在您的pom.xml

中假定以下依赖项
<properties>
    <version.cucumber>4.2.0</version.cucumber>
</properties>
<dependencies>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>${version.cucumber}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-guice</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>${version.cucumber}</version>
        <type>pom</type>
    </dependency>
</dependencies>

列出项目依赖项

$ mvn dependency:tree

将产生以下树

[INFO] +- io.cucumber:cucumber-java:jar:4.2.0:test
[INFO] |  \- io.cucumber:cucumber-core:jar:4.2.0:compile
[INFO] |     +- io.cucumber:cucumber-html:jar:0.2.7:compile
[INFO] |     +- io.cucumber:gherkin:jar:5.1.0:compile
[INFO] |     +- io.cucumber:tag-expressions:jar:1.1.1:compile
[INFO] |     +- io.cucumber:cucumber-expressions:jar:6.2.0:compile
[INFO] |     \- io.cucumber:datatable:jar:1.1.7:compile
[INFO] |        \- io.cucumber:datatable-dependencies:jar:1.1.7:compile
[INFO] +- io.cucumber:cucumber-testng:jar:4.2.0:compile
[INFO] |  \- org.testng:testng:jar:6.14.3:compile
[INFO] |     +- com.beust:jcommander:jar:1.72:compile
[INFO] |     \- org.apache-extras.beanshell:bsh:jar:2.0b6:compile
[INFO] +- io.cucumber:cucumber-guice:jar:4.2.0:test
[INFO] \- io.cucumber:cucumber-jvm:pom:4.2.0:compile

看看是否存在某种依赖关系

  • info.cuke:*任何版本
  • io.cucumber:cucumber-core 3之前的版本