Microsoft Exam Questions

You need to evaluate the unit test results

HOTSPOT
You are building an ASP.NET application. You develop the following unit test code. Line numbers are included
for reference only.
01 [TestClass]
02 public class UnitTest1
03 {
04 protected string _name;
05 protected float _expenses;
06 protected float _income;
07 protected float _payment;
08 protected float _balance;
09 public void AddCustomer(string name, float income, float payment, float balance)
10 {
11 _name = name;
12 _expenses = expenses;
13 _income = income;
14 _payment = payment;
15 _balance = balance;
16 CheckName();
17 DebRatio();
18 CheckBalance();
19 }
20 [TestMethod]
21 public void CheckName()
22 {
23 Assert.IsNotNull(_name, “CheckName failed unit test”);
24 }
25 [TestMethod]
26 public void DebRatio()
27 {
28 Assert.AreSame(_income, _payment, “DebRatio failed unit test”);
29 }
30 [TestMethod]
31 public void CheckBalance()
32 {
33 Assert.IsTrue(_balance >= 0.0f, Check balance failed unit test.”);
34 }
35}
You run the following line of code:
AddCustomer(“Contoso”, 0, 100, 100, -1);
You need to evaluate the unit test results. For each of the following statements, select Yes if the statement is
true. Otherwise, select No.
Hot Area:

Answer:

Explanation:
Box 1: Yes
Line 23 is Assert.IsNotNull(_name, “CheckName failed unit test”);
_name is “Contoso” so the assertion will succeed.
Box 2: No
Line 289 is Assert.AreSame(_income, _payment, “DebRatio failed unit test”);
_income is 0 and payment is 100. The assertion will fail.
Box 3: No
Line 33 is Assert.IsTrue(_balance >= 0.0f, Check balance failed unit test.”);_balance is -1. The assertion will fail.