用黄瓜java运行功能文件

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

我试图用java和intellij运行一个简单的功能文件,我似乎无法让它工作。

我设置了我的Cukes测试跑步者课程

package config;

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

@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true,
    features = {"src/test/resources/features/"},
    dryRun = false,
    glue = "com.ecs.googleuat"
)
public class RunCukesTest {
}

功能:功能:主页场景:主页鉴于我在主页上

步骤定义:

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;

public class MyStepdefs {
@Given("^I am on the home page$")
public void iAmOnTheHomePage() {
    System.out.println("Hello");
}
}

项目结构:

enter image description here

我正在使用java黄瓜插件的maven项目。

当我运行功能文件时,我收到以下错误:

未定义的步骤:鉴于我在主页上

1场景(1未定义)1步(1未定义)0m0.000s

您可以使用以下代码段实现缺少的步骤:

@Given("^I am on the home page$")
public void i_am_on_the_home_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

进程以退出代码0结束

请帮我理解我做错了什么。

谢谢

java intellij-idea cucumber cucumber-jvm
1个回答
0
投票

不是100%肯定,但我认为问题在于方法名称。简单的解决方案只是在MyStepdefs中复制粘贴建议的步骤定义并删除异常并添加你的println然后运行。也尝试去除你添加的胶水com.ecs.googleuat

请关注this以获得进一步的帮助!

虽然我会严格建议继续使用java-8

无论如何,如果你对Java-8感到满意。取下胶水inRunCukesTest.java。并更新你的MyStepdefs.java

  public class MyStepdefs implements En {
      public Stepdefs() {
        Given("^I am on the home page$", () -> {
           System.out.println("Hello");
        });
     }
 }

En自动为您实现默认胶水。

此外,使用适当的依赖项。跟着this一样。

编辑:对于Java 8,请确保如果您使用IntelliJ Idea,则启用Project SDK以启用1.8

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.