1private float minimumBalance = 10.00F; 2public float MinimumBalance 3{ 4 get{ return minimumBalance;} 5} 增加一个表明透支的异常;
1public class InsufficientFundsException : ApplicationException 2{ 3} 增加一个测试方法到AccountTest类中
1[Test] 2[ExpectedException(typeof(InsufficientFundsException))] 3public void TransferWithInsufficientFunds() 4{ 5 Account source = new Account(); 6 source.Deposit(200.00F); 7 Account destination = new Account(); 8 destination.Deposit(150.00F); 9 source.TransferFunds(destination, 300.00F); 10} 这个测试方法的[Test]属性有一个 [ExpectedException]属性,这表明这段测试代码期望得到某一类型的异常,如果这种异常没有出现在执行过程中,这车是失败,现在编译代码,启动NUnit Gui,这是测试条变红,提示错误信息: TransferWithInsufficentFunds : InsufficientFundsException was expected 让我们重新配置Account的代码,让它抛出异常,按下面的实例修改TransferFunds方法.
(编辑:焦作站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|