黄瓜@before背景和场景

时间:2016-12-07 21:09:33

标签: java gradle cucumber

好吧,我是黄瓜新手...... 我正在尝试为我的老师(uni)写的功能写一些测试defs 啊,我必须使用@before,我必须创建一个新的银行对象,然后每当我运行场景时,它都会为我创建一个新的银行对象...... 一切都很好,直到我得到功能的背景......所以功能看起来像这样......

>   Background: 
>     Given Ali is a customer
>     And Ali opens a current account with account number 4566
>     And Ali opens a current account with account number 8979
> 
>   Scenario: Deposits are logged in transaction logs
>     Given £29.99 is deposited into account 4566
>      When £9.01 is deposited into account 4566
>      Then Account 4566 has 2 transactions

现在我创建了一个新的银行,我运行后台步骤,然后当我们到达场景时@Before跳入并且它在这里创建新银行是它的代码...... @Before

 public void beforeScenario() {
        bank = new Bank();
    }

所以当我到达场景并尝试访问我通过背景创建的对象时,我得到一个空指针,这里是黄瓜结果..

 Background:                                                # All_transactions_are_logged.feature:7
    Given Ali is a customer                                  # StepDefs.is_a_customer(String)
    And Ali opens a current account with account number 4566 # StepDefs.opens_a_current_account_with_account_number(String,int)
    And Ali opens a current account with account number 8979 # StepDefs.opens_a_current_account_with_account_number(String,int)

  Scenario: Deposits are logged in transaction logs # All_transactions_are_logged.feature:12
    Given ú29.99 is deposited into account 4566     # StepDefs.is_deposited_into_account(String,long)
      java.lang.NullPointerException
        at my.bank.Account.deposit(Account.java:133)
        at my.bank.StepDefs.is_deposited_into_account(StepDefs.java:73)
        at ?.Given ú29.99 is deposited into account 4566(All_transactions_are_logged.feature:13)

    When ú9.01 is deposited into account 4566       # StepDefs.is_deposited_into_account(String,long)
    Then Account 4566 has 2 transactions

任何建议都有帮助... 请

0 个答案:

没有答案
相关问题