在黄瓜测试中使用特征文件中的值?

时间:2016-02-17 17:48:15

标签: java cucumber feature-file

有没有办法在特征文件中声明变量然后在黄瓜测试中使用?像这样:

myFile.feature

Given whenever a value is 50

myFile.java

@Given("^whenever a value is 50$")
public void testing(value) {
    assertEqual(value, 50);
}

老实说,我甚至不知道这会是什么样子。但我希望不必在功能文件和黄瓜测试中声明一个值。谢谢!

1 个答案:

答案 0 :(得分:3)

是的,你可以!在功能中写下给定步骤。

Feature: foobar

Scenario: something
    Given whenever a value is 50

然后将其作为JUnit测试运行。您将在控制台中看到类似的内容。

@Given("^whenever a value is (\\d+)$")
public void whenever_a_value_is(int arg1) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

然后您可以复制+粘贴它并将其更改为:

@Given("^whenever a value is (\\d+)$")
public void whenever_a_value_is(int value) {
    assertEquals(value, 50);
}
相关问题