I am coding some unit tests for a MVC 5 internet application.
Should I hard code the expected value in the Assert
line of code, or calculate this value from the input values before they have changed.
Here is an example:
I have a function that subtracts the correct balance from an Account
object where the Account
object has a subscriptionCostPerDay
and an accountBalance
.
Here is the code:
account1.subscriptionCostPerDay = 0.99M;
account1.accountBalance = 10;
The function that I am testing calculates the subscriptionCostPerDay
and subtracts this from the accountBalance
. In the above example, the accountBalance
should be 9.01 after the function call.
Should the Assert
statement hard code the value of 9.01, or should the expected value be calculated from the original object values?
Here are examples of the two different types I am referring to above:
1.
Assert.AreEqual(9.01M, account1Balance, "Account 1 has correct account balance");
2.
decimal expectedAccount1Balance = account1.accountBalance - account1.subscriptionCostPerDay;
Assert.AreEqual(expectedAccount1Balance, account1Balance, "Account 1 has correct account balance");
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire