有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在cucumber测试中使用特性文件中的值?

有没有办法在功能文件中声明一个变量,然后在cucumber测试中使用?比如:

我的文件。特征

Given whenever a value is 50

我的文件。爪哇

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

老实说,我甚至不知道这会是什么样子。但是我希望不必在特性文件和Cucumber测试中都声明一个值。谢谢


共 (1) 个答案

  1. # 1 楼答案

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

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