exam questions

Exam 70-486 All Questions

View all questions & answers for the 70-486 exam

Exam 70-486 topic 1 question 96 discussion

Actual exam question from Microsoft's 70-486
Question #: 96
Topic #: 1
[All 70-486 Questions]

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:

Show Suggested Answer Hide Answer
Suggested Answer:
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.

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
ex
Highly Voted 5 years, 7 months ago
It's AreSame, not AreEqual - checking if it's exactly the same object in memory. So (after params are fixed) the correct option is Y N N
upvoted 12 times
...
Aghie
Highly Voted 5 years, 10 months ago
AddCustomer("Contoso", 0, 100, 100, -1); this will get an error as the given code only has 4 params
upvoted 11 times
...
Leodolz
Most Recent 4 years, 5 months ago
We are missing a part on this question, because the AddCustomer() is supposedly taking 4 params, maybe expenses was supposed to be the 2nd param
upvoted 2 times
northgaterebel
4 years, 5 months ago
Exactly. Guess we cannot expect the test dump savants to proof read their own writing. It's what makes this study material an interesting challenge. Not only do we have to verify the answer but also the question lol.
upvoted 1 times
...
...
wel
4 years, 6 months ago
The arguments is lacking. They are only 4 arguments passed. string name, float income, float payment, float balance Which corresponds to below: _name = name; _expenses = expenses; _income = income; _payment = payment; _balance = balance; Is expense should also be on the parameters/arguments above? How come the line 33 is NO. Assert.IsTrue(_balance >= 0.0f, Check balance failed unit test."); Is -1 should be the value for balance here? AddCustomer("Contoso", 0, 100, 100, -1); Need explanation why only 4 arguments declared in AddCustomer.
upvoted 1 times
...
TimboJones
4 years, 8 months ago
What even is this quesion? That's not how unittests work, it certainly doesn't match the earlier questions in the slightest. Why is there an unattributed method in the TestClass that is accessing all three TestMethods!? We don't even need the TestMethods attribute, because it isn't run as a test method. Assert. will throw an exception when it's wrong. Which means if the first test fails, the rest won't even execute. And don't get me started on the wrong number of parameters and stuff. What even is this?!
upvoted 1 times
...
elevator44
4 years, 9 months ago
Code checked and it gives Yes, No, No https://dotnetfiddle.net/Fgl2j4 We are assuming that method "AddCustomer" receives all values in order how they are created and how they are handled inside of the method "AddCustomer" ("float expenses" is missing from question).
upvoted 1 times
...
mr_
5 years ago
Quote from explanation: " 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. " The assertion will fail, that is correct, but not because values are 0 and 100. Assertion would fail even if both _income and _payment would have the same value of 100. You should not compare value types using AreSame because they will never be same since they are boxed. I think that in the original question it could have been like both values are 100 so keep that in mind.
upvoted 1 times
...
rhysabray
5 years, 3 months ago
If you don't accept there is a typo in the question then all tests wont even run as there are too many arguments passed to the constructor. However; If you want to fix it your answer will depend on at what position in the list of arguments in the constructor you place the missing "expenses" value. Personally I've placed it just after the string to match the order the properties were declared like so: AddCustomer(string name, FLOAT EXPENSES, float income, float payment, float balance) Doing so I make the answer as Y, N, N. Yes - as the string is not null, it is "contoso". No - as even though in my case 100 == 100 they are still separate objects. Assert.AreSame != Assert.AreEqual as described by @ex No - as balance = -1, which is not >= 0, hence resolves to false Depending on how you 'fix' the constructor you may get different results.
upvoted 3 times
...
OS
5 years, 10 months ago
code snipped: public void AddCustomer(string name, float income, float payment, float balance) test-values: AddCustomer(“Contosoâ€, 0, 100, 100, -1); Solution 1: add 'string expenses,' as second parameter to the code snipped - the test-values will fit in the answers will be Y Y N Solution 2: In case only the first 4 test-values will be taken from the code the answers will be Y N Y
upvoted 2 times
...
Aghie
5 years, 10 months ago
AddCustomer(string name, float income, float payment, float balance)
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...