无法在QAFTestStepProvider类中传递实例变量

问题描述 投票:2回答:1

我得到一个NullPointerException,用于在带有@Given注释的方法中实例化的实例变量,如下面的代码“test”所示:

import com.qmetry.qaf.automation.step.QAFTestStepProvider;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

@QAFTestStepProvider
public class Steps
{
    String test;

    @Given("^Step 1$")
    public void step1()
    {
        test = "test_string";
    }

    @Then("^Step 2$")
    public void step2()
    {
        String[] list = test.split("_");
    }
}

我已经看到各种例子(second to last code example)和资源(first paragraph of this answer)说这应该没问题,因为DI只有在尝试在Step Definition Java类之间共享状态时才需要,而不是在类本身之间。

有什么我想念的东西或有没有办法使这项工作?

java bdd cucumber-jvm qaf
1个回答
0
投票

根据qaf-release-notes-2.1.9,您需要将step.provider.sharedinstance设置为true(默认值为false)。在应用程序属性中,您可以指定

step.provider.sharedinstance=true

© www.soinside.com 2019 - 2024. All rights reserved.