2017-03-07 86 views
1

我得到了在與@Given註釋的方法實例的實例變量一個NullPointerException如下面的代碼中的「測試」:無法通過實例變量在QAFTestStepProvider

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),說這應該很好,因爲只有當試圖在Step Definition Java類之間共享狀態時,DI纔是必需的,而不是在類本身內。

有什麼我失蹤或有沒有辦法讓這項工作?

+0

您正在使用哪個版本的qaf? – user861594

回答

0

根據qaf-release-notes-2.1.9您需要將step.provider.sharedinstance設置爲true(默認值爲false)。在應用程序屬性中,您可以指定

step.provider.sharedinstance=true