无法在 QAFTestStepProvider 中传递实例变量 Class
Cannot Pass Instance Variables Within QAFTestStepProvider Class
我得到了实例变量的 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) and resources(first paragraph of this answer) 说这应该没问题,因为只有在尝试在步骤定义 Java classes 之间共享状态时才需要 DI , 不在 class 本身内。
有没有我遗漏的东西,或者有什么方法可以让它发挥作用吗?
根据 qaf-release-notes-2.1.9,您需要将 step.provider.sharedinstance
设置为 true
(默认值为 false
)。在应用程序属性中,您可以指定
step.provider.sharedinstance=true
我得到了实例变量的 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) and resources(first paragraph of this answer) 说这应该没问题,因为只有在尝试在步骤定义 Java classes 之间共享状态时才需要 DI , 不在 class 本身内。
有没有我遗漏的东西,或者有什么方法可以让它发挥作用吗?
根据 qaf-release-notes-2.1.9,您需要将 step.provider.sharedinstance
设置为 true
(默认值为 false
)。在应用程序属性中,您可以指定
step.provider.sharedinstance=true