我在编写两个字符串时遇到问题... 我知道它很基本,但由于某种原因它不起作用...... 这是代码......
Customer customer;
for (int i = 0; i < this.getCustomers().size(); i++) {
customer = this.getCustomerById(i);
if (customer.getFullName().toLowerCase().equals( name.toLowerCase())) {
return customer;
}
}
return new Customer();
customer.getFullName()。toLowerCase()。equals(name.toLowerCase())这里我比较两个字符串,事情是如果我在黄瓜测试期间调用该方法它给我这个错误...
And Jim opens a current account with account number 234 # StepDefs.opens_a_current_account_with_account_number(String,int) java.lang.NullPointerException at my.bank.Bank.getCustomerByName(Bank.java:111) at my.bank.StepDefs.opens_a_current_account_with_account_number(StepDefs.java:38) at ?.And Jim opens a current account with account number 234(Customer_can_open_accounts.feature:28)
但是如果我在main方法中创建这些步骤的草稿并使用相同的参数调用它们的工作.... 这是草案......
is_a_customer("Jim");
is_a_customer("Bob");
opens_a_savings_account_with_account_number("Jim", 123);
如果我调试它一步一步地执行代码它会做什么预期最终它将客户和帐户存储在银行... 但由于某种原因,当我进行黄瓜测试时,它不起作用,这里是黄瓜stepdef ...
public void opens_a_current_account_with_account_number(String customerName, int accountNumber) throws Throwable {
Account ac = new Account();
ac.setAccountNumber(accountNumber);
Customer customer = bank.getCustomerByName(customerName);
ac.addAccountOwner(customer.getId());
customer.addCustomerAccounts(ac.getAccountId());
bank.addAccount(ac);
}
除了GRALDE CUCUMBER - DEBUG之外,我没有办法调试黄瓜测试,但这并不是真正有用的帮助....