我的单元测试始终处于待审状态

时间:2016-03-29 16:39:46

标签: c# wpf unit-testing

第一次尝试使用单元测试。我要完成我的步骤:

  1. 我的项目的右键单击解决方案我想在visual studio中测试并点击“新项目”。然后我选择了测试>测试项目。

  2. 这给了我另一个项目,我的解决方案下有一个Test.cs文件。我在其中添加了以下内容:

    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());
        }
    }
    

    }

  3. 我原来的项目名为Project1。在我的测试项目中,我添加了对Project1的引用。

    现在,我的测试显示在测试视图中,但是尝试运行它只是暂时待命。我尝试了另一个人的项目w / tests,它做了同样的事情。不确定我需要做什么。没有任何运气窥探谷歌。

    编辑:当我尝试运行它时,这是一些Debug输出:

    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).
    

    一直持续到我离开视觉工作室。

    编辑:看到有关visual studio 2010的问题没有服务包1的问题1.结果我没有。现在更新,希望它有效。

1 个答案:

答案 0 :(得分:0)

visual studio 2010更新为service pack 1解决了问题,我的测试现在正常运行。

通过以下链接明白了这一点:VS2010 Unit test “Pending” and the test cannot be completed