黄瓜JVM - @When不能被解析为一个类型

问题描述 投票:1回答:1

我下面this tutorial设立BDD在Java项目中使用黄瓜JVM。我已经设置了下面的测试文件下,我在Eclipse的Java项目我src/test/java文件夹:

cucumber test.Java

package myPackage;

import static org.junit.Assert.fail;

import java.io.IOException;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;


@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:Feature")
public class CucumberTest {

    // error on line below 'When cannot be resolved to a type'
    @When("^the step is invoked$")
    public void myTestMethod() throws IOException {

    }   
}

我敢肯定,这是简单的东西(我是比较新的黄瓜为Java应用程序),而且我相信我做的这一切在正确的位置。如何解决这个错误吗?使用CTRL+SHIFT+O(组织导入)不会自动导入不管它是什么,我需要,我也找了相关的包我可能需要进口,下cucumber.apicucumber.api.junitcucumber.api.junit.Cucumber命名空间,并且似乎没有对任何东西还有,我应该进口。我查看了相似的,所以问题,并没有发现任何线索,我的问题是更具体。

java eclipse bdd cucumber-jvm
1个回答
0
投票

感谢@racraman的提示。我用的是旧版本的黄瓜,JVM Maven的依赖关系:

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>1.2.5</version>
        <type>pom</type>
    </dependency>
     -->
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

我取代了这些对于使用io.cucumber <groupId>向上最新的依赖

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.2.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>4.2.2</version>
        <scope>test</scope>
    </dependency>

现在我可以导入相关的注释:

 import cucumber.api.java.en.When;
© www.soinside.com 2019 - 2024. All rights reserved.