VS2013???????????VS2013????????????
???????????? ???????[ 2014/9/15 11:53:16 ] ??????????????? ???????
????1????VS3013?????????????????????У?LearnUnitTest?????????????LearnUnitTest_Bank???????????????BankAccount??????????е???????????????????
????2????LearnUnitTest????????????????????????????????=?????=????????=??VisualC#=??????=??????????????????????LearnUnitTest_BankTest????LearnUnitTest_Bank????LearnUnitTest_BankTest????????????????????LearnUnitTest_BankTest???????????????????BankAccountTest??
????????BankAccountTest???????????TestClass?????????????TestMethod???????????????????????????????????????????á?
?????????
????3?????????????BankAccount???Debit??????????????????β??????????·??棺
????a????????????credit amount)??????????÷???????ArgumentOutOfRangeException
????b????????????С??0?????
????c?????a??b???????÷????????????????amount????????????
?????????a??b??c???????BankAccount???е?Debit??????????????-=????????+=——?????????????????μ?bug???????????????????????β????а????????????????????
???????????????????·???????Debit??????
// unit test code
[TestMethod]
public void Debit_WithValidAmount_UpdatesBalance()
{
// arrange
double beginningBalance = 11.99;
double debitAmount = 4.55;
double expected = 7.44;
BankAccount account = new BankAccount("Mr. Bryan Walton"?? beginningBalance);
// act
account.Debit(debitAmount);
// assert
double actual = account.Balance;
Assert.AreEqual(expected?? actual?? 0.001?? "Account not debited correctly");
}
????????????????
???????????TestMethod????????????void???????в?????
??????????????????????bug????+=???-=???ɡ?
???????????????????
????????????Debit?????β?????????????????
????a?????credit amount??????????debit amount????balance????????ArgumentOutOfRangeException
????b?????credit amount??0С?????ArgumentOutOfRangeException??
????(1)???????????
??????γ??????????????????????????????
????????
//unit test method
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange()
{
// arrange
double beginningBalance = 11.99;
double debitAmount = -100.00;
BankAccount account = new BankAccount("Mr. Bryan Walton"?? beginningBalance);
// act
account.Debit(debitAmount);
// assert is handled by ExpectedException
}
????????????????Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange??????????debit amountС??0??????β????????±????????????ArgumentOutOfRange?????????β???????????д?????????????Debit??????????β???????——????νTDD??????
?????????????ExpectedExceptionAttribute??????????????????????????????????????ArgumentOutOfRangeException???????????????2????????????β?????????????????????debitAmount???????????????????????????????Debit???????????£???demit amountС??0???????ApplicatinException??????????Щ????????β?????????????
??????????debit amount ????balance?????Σ??????????漸????????
????a??????????μ??????????С???????Debit_WhenAmountIsMoreThanBalance_ShouldThrowArgumentOutOfRange
????b????????????????
????Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange
????????????嵽?????????
????c????debitAmount??????????balance????
??????2?????в??????
?????ò????debitAmount?????Debit_WhenAmountIsMoreThanBalance_ShouldThrowArgumentOutOfRange
?????? Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange
???????????????????????????????趨??????cases???????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11