Cucumber V4 [io.cucumber]无法识别@ Given / When / Then并给出错误“无法解决导入的黄瓜。api.java.en.When”

时间:2019-02-07 08:47:36

标签: cucumber

I am migrating from Cucumber Version 1.2.4 [<groupId>info.cukes</groupId>] to V.4.2.2 <groupId>io.cucumber</groupId>. After this, Cucumber Framework is not able to identify @Given/When/Then annotations and given error – The import cucumber.api.java.en.Given/When/Then cannot be resolved

Eclipse suggesting to add below dependency. But my thought is when I am migrating to Cucumber V4(io.cucumber) then why shall I add dependency of V1.2.4(info.cukes). Can someone suggest which is the correct dependency I shall add under V4 i.cucumber. which import i shall add to fix this issue. Can it be resolved without adding info.cukes -> cuucmber-java(1.2.4)

    <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.4</version>
    </dependency>

以下是我在POM.xml下添加的依赖项列表。都是io.cucumber依赖项。

   <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-core</artifactId>
                <version>4.2.2</version>
            </dependency>

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

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

            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-jvm-deps</artifactId>
                <version>1.0.6</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>gherkin</artifactId>
                <version>6.0.14</version>
            </dependency>

            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>1.10.19</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-testng</artifactId>
                <version>2.0.0</version>
            </dependency>

            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-picocontainer</artifactId>
                <version>2.1.0</version>
                <scope>test</scope>
            </dependency>

请帮助我了解如何在黄瓜v4下解决该错误。我不想使用info.cukes Maven ID,因为它没有V4。所以请指导

2 个答案:

答案 0 :(得分:0)

我已经解决了该问题,并共享了正确的依赖关系集。请根据您的框架要求添加JUnit / TestNG。

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

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

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

     <!-- https://mvnrepository.com/artifact/io.cucumber/datatable -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>datatable</artifactId>
    <version>1.1.12</version>
</dependency>

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>4.2.3</version>
</dependency>

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.2.3</version>
    <scope>test</scope>
</dependency>

答案 1 :(得分:0)

Maven似乎停止使用<groupId>info.cukes</groupId>黄瓜Java,而不是使用<groupId>io.cucumber</groupId>

因此,从(<groupId>io.cucumber</groupId><artifactId>cucumber-java</artifactId>的4.7.0版本开始,不再支持cucumber.api.java.en.Given/When/Then

您可以使用import io.cucumber.java.en.Given(/When/Then)替换它。