Reputation: 1955
First time attempting to use unit tests. I'm going to go through my steps:
Right clicked solution of my project I want to test in visual studio and clicked 'new project'. Then I selected Test > Test Project.
This gave me another project under my solution with a Test.cs file. I added the following to it:
namespace TestProject1
{
[TestClass]
public class MainTest
{
//Project1.MainWindow mw = new Project1.MainWindow(); //not used in test yet
[TestMethod]
public void MakeDoubleDate_Test()
{
string validMpacString = "1998,265/302010"; //When converted, should be 36060.430902777778
string nonValidString1 = "nope,700/807060";
string nonValidString2 = "thisDoesn't work";
double validDouble = Project1.ConversionsUnit.MakeDoubleDate(validMpacString);
double nonValidDouble1 = Project1.ConversionsUnit.MakeDoubleDate(nonValidString1);
double nonValidDouble2 = Project1.ConversionsUnit.MakeDoubleDate(nonValidString2);
Assert.AreEqual(validDouble, 36060.430902777778);
Assert.AreEqual(nonValidDouble1, DateTime.Now.ToOADate());
Assert.AreEqual(nonValidDouble2, DateTime.Now.ToOADate());
}
}
}
My original project is called Project1
. In my test project, I added a reference to Project1
.
Now, my test shows up in the test view, but trying to run it it just is stuck on pending forever. I tried another person's project w/ tests and it did the same thing. Not sure what I need to do. Haven't had any luck snooping around google.
Edit: Here's some Debug output when I try running it:
The thread 'ExecutionUtilities.InvokeWithTimeout helper thread 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter.AbortTestRun'' (0x4748) has exited with code 0 (0x0).
The thread 'Agent: adapter run thread for test 'MakeDoubleDate_Test' with id '1bc08c40-ee7f-46e5-8689-8237cd3ffe4b'' (0x2820) has exited with code 0 (0x0).
The thread 'Agent: state execution thread for test 'MakeDoubleDate_Test' with id '1bc08c40-ee7f-46e5-8689-8237cd3ffe4b'' (0x1848) has exited with code 0 (0x0).
The thread 'Agent: test queue thread' (0x3ecc) has exited with code 0 (0x0).
W, 18160, 8, 2016/03/29, 12:52:54.995, USERNAME\QTAgent32.exe, AgentObject.AgentStateWaiting: Proceeding to clean up data collectors since connection to controller is lost
The thread 'Agent: heartbeat thread' (0x4560) has exited with code 0 (0x0).
The thread '<No Name>' (0x2284) has exited with code 0 (0x0).
The thread '<No Name>' (0x4484) has exited with code 0 (0x0).
The thread '<No Name>' (0x43f4) has exited with code 0 (0x0).
The thread '<No Name>' (0x3a50) has exited with code 0 (0x0).
The thread '<No Name>' (0x4424) has exited with code 0 (0x0).
Which continues until I exit out of visual studio.
Edit: Saw something about visual studio 2010 having problems w/o service pack 1. Turns out I don't have it. Updating now, hopefully it works.
Upvotes: 4
Views: 2927
Reputation: 1955
Updating my visual studio 2010
to service pack 1
solved the issue and my tests run correctly now.
Got the idea to do so from this link: VS2010 Unit test “Pending” and the test cannot be completed
Upvotes: 1