运行 发生异常后的清理代码 (Java/Cucumber)
Run cleanup code after exception has occured (Java/Cucumber)
我有一个黄瓜方法,可以在测试完成后进行一些清理。
@After("@First")
public void resetUsers() throws BankServiceException_Exception {
bank.retireAccount(customerBankID);
bank.retireAccount(merchantBankID);
}
然而,此方法不是 运行,以防其中一个测试抛出异常,然后清理不会发生。
有没有办法让清理逻辑一直发生?即使发生了异常?
@After("@First") -Its a tagged hook,i.e. this hook will run only after those scenarios which are having tags @First ,if you want to execute a method which should be run after each scenario ,use hooks without any tag as given below-
@After
public void resetUsers() throws BankServiceException_Exception {
bank.retireAccount(customerBankID);
bank.retireAccount(merchantBankID);
}
我有一个黄瓜方法,可以在测试完成后进行一些清理。
@After("@First")
public void resetUsers() throws BankServiceException_Exception {
bank.retireAccount(customerBankID);
bank.retireAccount(merchantBankID);
}
然而,此方法不是 运行,以防其中一个测试抛出异常,然后清理不会发生。
有没有办法让清理逻辑一直发生?即使发生了异常?
@After("@First") -Its a tagged hook,i.e. this hook will run only after those scenarios which are having tags @First ,if you want to execute a method which should be run after each scenario ,use hooks without any tag as given below-
@After
public void resetUsers() throws BankServiceException_Exception {
bank.retireAccount(customerBankID);
bank.retireAccount(merchantBankID);
}