TransferWithInsufficentFunds : InsufficientFundsException was expected 让我们再一次修复Account代码,按如下方法修改TransferFunds:
public void TransferFunds(Account destination, float amount)
{
destination.Deposit(amount);
if(balance-amount throw new InsufficientFundsException(); Withdraw(amount); } 编译并运行测试-绿色的状态条。成功了!但是等等,看看我们刚才编写的代码,我们会发现银行可能在每个没有成功的转帐操作失去一笔钱。让我们编写一个测试来证明我们的疑虑,增加如下测试方法: [Test] public void TransferWithInsufficientFundsAtomicity() { Account source = new Account(); source.Deposit(200.00F); Account destination = new Account(); destination.Deposit(150.00F); try { source.TransferFunds(destination, 300.00F); } catch(InsufficientFundsException expected)
文章来源于领测软件测试网 https://www.ltesting.net/