1public void TransferFunds(Account destination, float amount) 2{ 3 destination.Deposit(amount); 4 if(balance-amount < minimumBalance) 5 throw new InsufficientFundsException(); 6 Withdraw(amount); 7} 编译,运行测试-测试条变绿,成功了,但是,我们看看这个代码,我们仅仅写了我们可以看到的转帐操作中的错误,现在让我们来写一个测试来证实我们不确定的错误,添加下面一个测试方法
1[Test] 2public void TransferWithInsufficientFundsAtomicity() 3{ 4 Account source = new Account(); 5 source.Deposit(200.00F); 6 Account destination = new Account(); 7 destination.Deposit(150.00F); 8 try 9 { 10 source.TransferFunds(destination, 300.00F); 11 } 12 catch(InsufficientFundsException expected) 13 { 14 } 15 Assert.AreEqual(200.00F,source.Balance); 16 Assert.AreEqual(150.00F,destination.Balance); 17} 编译运行—红色测试条,我们算错了300元,代码显示正确的结果是150元,但账户显示确是450,那么怎样修补错误,能不能加一段最小基金检测在资金处理之前呢?我们可以在catch块中加以一些修补方法,或依靠我们的管理人员修复对象的规定,我们需要在多方面回答这些问题,但不是在现在,那在此期间我们可以怎么做呢?移出它?一个最好的方法是忽视它,添加以下属性在你的测试方法中
(编辑:焦作站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|