黄瓜测试。特征没有看到我的步骤

时间:2017-04-23 09:43:32

标签: automated-tests cucumber gherkin

我想开始用黄瓜测试,创建了最简单的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的黄瓜 - 小黄瓜 文件结构是:

enter image description here

此外,test / java文件夹在Maven中标记为Test Source Folder。 我也尝试在Maven中重启IntelliJ和Reimport项目,没有任何帮助。有什么建议吗?

1 个答案:

答案 0 :(得分: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),它有效:)

相关问题