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:

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.



Leave a Reply 8

Your email address will not be published. Required fields are marked *


Gowri

Gowri

public void AddCustomer(string name, float income, float payment, float balance)

Expenses parameter is not included, then the whole question is wrong.

Manu

Manu

Question broken – needs fixing.

S

S

Assuming AddCustomer takes the values in the following order:
_name, _expenses, _income, _payment, _balance
(The same order they are listed in the constructor), and that the parameters listed were a typo:

23 = PASS (The name is not null)
28 = FAIL (_income and _payment are both 100, so they are EQUAL, but not the SAME object.)
33 = FAIL (Not >= 0)

Gug

Gug

What about the answer which says:

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.

so it considers

_income == 0

I think your assumption is wrong

Gug

Gug

but you are right about AreSame 😉