简体   繁体   English

我已经使用Java在Eclipse中建立了一个简单的自动化框架,但是无法通过Junit运行Cucumber测试

[英]I've set up a simple automation framework in Eclipse using Java but cannot run Cucumber tests via Junit

I'm new to Cucumber and Java (come from a Specflow/C# background). 我是Cucumber和Java的新手(来自Specflow / C#背景)。 I am trying to set up my first project in eclipse and think everything is set up correctly (my step definition file can be accessed (using F3 - go to definition) from the feature file). 我试图在eclipse中设置我的第一个项目,并认为一切都已正确设置(可以从特征文件访问(使用F3-转到定义)我的步定义文件)。

I have set up a testrunner file like so: 我已经建立了一个testrunner文件,如下所示:

package cucumberTest;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "Feature"
        ,tags = "@LoginTests"
        ,glue={"src/stepDefinition"}
        ,dryRun = true
        ,monochrome = true
        )

public class TestRunner {
}

My issue is that when I run Junit (v4.11) via Eclipse IDE, the tests do not run, I get told the scenarios and steps are undefined and am given suggestions to fix the issue: 我的问题是,当我通过Eclipse IDE运行Junit(v4.11)时,测试没有运行,我被告知场景和步骤未定义,并给出了解决问题的建议:

2 Scenarios (2 undefined)

6 Steps (6 undefined)

0m0.105s

You can implement missing steps with the snippets below:

Given("^User is on Home Page$", () -> {

    //Write code here that turns the phrase above into concrete actions

throw new PendingException();

});

However, the syntax suggested to me is incorrect. 但是,向我建议的语法不正确。 Any ideas why the syntax is wrong and why my tests do not run? 有什么想法为什么语法错误以及为什么我的测试无法运行?

The suggested syntax (snippets) is for java8. 建议的语法(摘要)适用于java8。 If you want to use regular java syntax, use cucumber-java dependency rather than cucumber-java8 dependency. 如果要使用常规的Java语法,请使用Cucumber-java依赖性而不是Cucumber-java8依赖性。

The reason you are getting the message that your steps are undefined, is because Cucumber cannot find your glue. 之所以收到消息,说明您的步骤未定义,是因为Cucumber无法找到您的胶水。 Make sure you are providing the correct location of your step definitions in the cucumber options for "glue=". 确保在“ glue =“的黄瓜选项中提供正确的步骤定义位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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