简体   繁体   English

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

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

Is there any way to declare a variable in a feature file to then use in a cucumber test? 有没有办法在特征文件中声明变量然后在黄瓜测试中使用? Something like this: 像这样的东西:

myFile.feature myFile.feature

Given whenever a value is 50

myFile.java myFile.java

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

Honestly, I don't even know what this would look like. 老实说,我甚至不知道这会是什么样子。 But I would love to not have to declare a value in both the feature file AND the Cucumber test. 但我希望不必在功能文件和黄瓜测试中声明一个值。 Thanks! 谢谢!

Yes you can! 是的你可以! Write the Given-step in the feature. 在功能中写下给定步骤。

Feature: foobar

Scenario: something
    Given whenever a value is 50

Then run it as a JUnit test. 然后将其作为JUnit测试运行。 You will see something like this in the console. 您将在控制台中看到类似的内容。

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

Then you can copy+paste it and change it to: 然后你可以复制+粘贴它并将其更改为:

@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