获取&#34;类<cucumber>无法解析为类型&#34;设置JUnit时的Cucumber.class

时间:2016-11-15 05:31:24

标签: junit cucumber

我使用Cucumber 1.2.2 jar并收到错误&#34; Class无法解析为类型&#34;对于以下代码。 有人可以建议解决方案。

Eclipse Code

4 个答案:

答案 0 :(得分:3)

您应该进行此导入 - import cucumber.api.junit.Cucumber;

Eclipse将鼠标悬停在错误上方显示这些选项。

答案 1 :(得分:1)

我删除了pom.xml文件中的黄瓜-junit依赖关系范围,并且将解决错误“无法解析导入的黄瓜.api.junit”。

答案 2 :(得分:0)

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
//The import cucumber.api.junit cannot be resolved
import cucumber.api.junit.Cucumber;
////Receiving an error message as Class<Cucumber> cannot be resolved to a type
@RunWith(Cucumber.class)

@CucumberOptions(
        features = "C:\\Users\\achelimi\\eclipse-workspace\\FirstAppl\\src\\main\\java\\feature\\login.feature", 
        glue = {"stepDefinition" }, 
        plugin = { "pretty", "html:test-outout", "json:json_output/cucumber.json",
                "junit:junit_xml/cucumber.xml" }, 
        monochrome = true, 
        strict = true, 
        dryRun = false)
public class TestRunner {

}

//Added below Dependencies for POM.xml

    <dependencies>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-picocontainer</artifactId>
                <version>1.2.5</version>
            </dependency>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>4.2.0</version>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-jvm</artifactId>
                <version>1.2.5</version>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>net.sourceforge.cobertura</groupId>
                <artifactId>cobertura</artifactId>
                <version>2.1.1</version>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-jvm-deps</artifactId>
                <version>1.0.5</version>
            </dependency>
            <dependency>
                <groupId>net.masterthought</groupId>
                <artifactId>cucumber-reporting</artifactId>
                <version>1.0.0</version>
            </dependency>
//Added below Dependencies for POM.xml
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>gherkin</artifactId>
                <version>2.12.2</version>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>2.0.2-beta</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
//Added below Dependencies for POM.xml
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.0.1</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/info.cukes/gherkin-jvm-deps -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>gherkin-jvm-deps</artifactId>
                <version>1.0.2</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-html</artifactId>
                <version>0.2.3</version>
            </dependency>
   //Added below Dependencies for POM.xml

 //Added below Dependencies for POM.xml
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.6</version>
            <scope>system</scope>
            <systemPath>C:\Program Files\Java\jdk1.8.0_202\lib\tools.jar</systemPath>
        </dependency>
    </dependencies>

答案 3 :(得分:0)

第1步:手动编写import语句,错误将消失。

导入cumul.api.junit.Cucumber;

第2步:同样,删除pom.xml文件中的黄瓜-junit依赖范围