java - Cucumber Runner 类未运行步骤定义

标签 java cucumber gherkin

我正在使用 Cucumber 和 Java 编写自动化测试。

我可以通过右键单击我的功能文件并将其作为 Cucumber 功能运行来运行步骤定义,并且所有步骤都会成功通过。

但是,我需要使用 Runner 类来运行它们。

我的功能文件位于此文件夹中:

src/test/java/features

我的步骤定义位于此文件夹中:

src\test\java\com\abc\commercial\def\automation

我的运行者类也存储在

src\test\java\com\abc\commercial\def\automation

这是 Runner 类代码:

@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = {"progress",
            "html:build/report/html",
            "junit:build/report/junit/cucumber-report.xml",
            "json:build/report/json/cucumber-report.json"
    },
    glue = {"src\\test\\java\\com\\abc\\commercial\\def\\automation"},
    features = {"src/test/java/features"}
    )
public class QARunner {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    }
}

当我将 Runner 类作为 JUnit 测试运行时,我在控制台中收到以下响应:

UUUUUUUUU

Undefined scenarios:
src/test/java/features/US46052
src/test/java/features/postFeatures.feature:43 # As the

2 Scenarios (2 undefined)
9 Steps (9 undefined)
0m0.303s


You can implement missing steps with the snippets below:

@Given("the Application...")
public void the_Application...() {

因此步骤定义不会被选取。

这与我的测试运行器所在的位置有关吗? 我认为它没有获取自动化文件夹中的步骤定义

感谢您的帮助

最佳答案

试试这个:不需要 main 方法。 glue 选项应采用封装样式。

@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = {"progress",
            "html:build/report/html",
            "junit:build/report/junit/cucumber-report.xml",
            "json:build/report/json/cucumber-report.json"
    },
    glue = {"com.abc.commercial.def.automation"},
    features = {"src/test/java/features"}
    )
public class QARunner {

}

关于java - Cucumber Runner 类未运行步骤定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50723798/

相关文章:

java - Selenium/Java/Junit - 获取运行测试时使用的驱动程序/浏览器

java - 如何替换数组中字符串索引的值

ruby - 用正则表达式替换文本 Ruby Capybara

angularjs - 当我有 Cucumber 和 Selenium 时,为什么还需要 Protractor?

java - 无法找到存在的元素,获取 NullPointerException 而不是 NoSuchElement

java - 实例化后为空 TableModel

java - EWS java.lang.NoSuchMethodError : org. joda.time.format.DateTimeFormatter.withZoneUTC

cucumber - 在 BDD 用户故事/验收测试中混合“此时”和“何时”

ruby-on-rails - 如何在 cucumber + capybara 步骤定义中设置 HTTP_REFERER?

testing - 在步骤定义类中包含非步骤方法是否可以接受?