繁体   English   中英

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

[英]Use a value in a feature file in a cucumber test?

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

myFile.feature

Given whenever a value is 50

myFile.java

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

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

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

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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM