Answered by:
Unit test not working

Question
-
Here is my simple test...
using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using VPGP.GPGKeys; namespace Tests { [TestClass] public class UnitTest1 { [TestMethod] public void Test_GPGKeys_Key_SetID1() { ulong keyID; Key key1 = new Key(); key1.SetID("731A0C77BDBF656E"); keyID = 0x731A0C77BDBF656EL; Assert.AreEqual(key1.ID, keyID); } [TestMethod] public void Test_GPGKeys_Key_SetID2() { ulong keyID; Key key1 = new Key(); keyID = 0x9EEFE448EEB63AB1L; key1.SetID(keyID); Assert.AreEqual(key1.sID, "one"); } } }
I referenced VPGP, a library project. I also reference Microsoft.VisualStudio.QualityTools.UnitTestFramework.
I build and try to run it, I also try to debug it. But it doesn't run at all. There are no error messages, and it claims the test passed. The last Assert.AreEqual(key1.sID, "one"); is to make it fail so that I know it was running. It didn't fail, which means it didn't run.
So, what's wrong?
VP
Saturday, August 15, 2015 2:53 AM
Answers
-
1. I redesigned my objects.
2. I then shut down solution and manually deleted the /bin and /obj directories.
3. I made a new test and ran it successfully. I made it "fail" successfully... then I corrected the test and made it "pass" successfully. I set break point and it stopped on the break point.
So, lesson learned, #2 is an important step.
VP
- Proposed as answer by Herro wongMicrosoft contingent staff Wednesday, August 19, 2015 7:40 AM
- Marked as answer by Violoncello Passionato Wednesday, August 19, 2015 11:32 AM
Tuesday, August 18, 2015 2:03 PM
All replies
-
Hi VP,
Find the test drop down menu in Visual studio you are using. You will find a button to start running all unit tests. Click to get it started, and then a test explorer window will show the test result.
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Monday, August 17, 2015 4:24 AM -
> Click to get it started, and then a test explorer window will show the test result.
As I said, I did this... it claimed the test was successful. The problem is I can't accept the claimed result. I put in something I knew would fail.
Assert.AreEqual(key1.sID, "one");
The problem is, this line didn't fail. I put a break point, but the debugger wouldn't stop on it. I put more break points, but none of them stopped. So I have doubt that it ever started.
VP
Monday, August 17, 2015 1:00 PM -
>> I put a break point, but the debugger wouldn't stop on it. I put more break points, but none of them stopped. So I have doubt that it ever started.
Try the following SO link to see how to debug the unit tests. http://stackoverflow.com/questions/4103712/stepping-through-and-debugging-code-in-unit-tests
>> The problem is, this line didn't fail
I used a code sample to test you scenario, I could see test fail when using incorrect string. My test code snippet.
assembly code .
namespace VPGP { public class Key { public string SetID (string id){ return id + "hello,world"; } } }
unit test.
[TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { VPGP.Key key1 = new VPGP.Key(); string key= key1.SetID("731A0C77BDBF656E"); string keyID = "731A0C77BDBF656Ehello,world"; Assert.AreEqual(key, "one"); } }
If you still cannot make it work, please post a repro code sample. I will review and let you know my result.
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Tuesday, August 18, 2015 7:05 AM -
1. I redesigned my objects.
2. I then shut down solution and manually deleted the /bin and /obj directories.
3. I made a new test and ran it successfully. I made it "fail" successfully... then I corrected the test and made it "pass" successfully. I set break point and it stopped on the break point.
So, lesson learned, #2 is an important step.
VP
- Proposed as answer by Herro wongMicrosoft contingent staff Wednesday, August 19, 2015 7:40 AM
- Marked as answer by Violoncello Passionato Wednesday, August 19, 2015 11:32 AM
Tuesday, August 18, 2015 2:03 PM