【问题标题】:Cucumber test.feature doesn't see my stepsCucumber test.feature 没有看到我的步骤
【发布时间】:2017-04-23 09:43:31
【问题描述】:

我想用 cucumber 开始测试,创建了最简单的 test.feature 文件:

Feature: XYZ
 Scenario: S1
  When I am on x page
  Then I see the element

并创建步骤

import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

    public class MyStepdefs {
        @When("^I am on x page$")
        public void iAmOnXPage() {
            System.out.println("I'm on page");
        }

        @Then("^I see the element$")
        public void iSeeTheElement() throws Throwable {
            System.out.println("I see dead people");
        }
    }

我已经安装了所有需要的插件: - Java的黄瓜 - Groovy 的黄瓜 - 小黄瓜 文件结构为:

此外,test/java 文件夹在 Maven 中被标记为测试源文件夹。 我还尝试在 Maven 中重新启动 IntelliJ 和 Reimport 项目,没有任何帮助。有什么建议吗?

【问题讨论】:

    标签: automated-tests cucumber gherkin


    【解决方案1】:

    好的,我找到了解决方案,我创建了额外的 testRunner 类:

    import cucumber.api.junit.Cucumber;
    import org.junit.runner.RunWith;
    import cucumber.api.CucumberOptions;
    
    @RunWith(Cucumber.class)
    @CucumberOptions(
            features={"src/test/resources"}
    )
    
    public class testRunner {
    }
    

    在我检查过的几个教程中没有提到它,但在 https://www.stevefenton.co.uk/2015/01/getting-started-with-bdd-intellij/ 中找到了它 经过小的改动(例如@Cucumber.Options -> @CucumberOptions)它工作了:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多