C# 我的单元测试总是挂起

C# 我的单元测试总是挂起,c#,wpf,unit-testing,C#,Wpf,Unit Testing,第一次尝试使用单元测试。我将完成以下步骤: 右键单击要在visual studio中测试的项目的解决方案,然后单击“新建项目”。然后我选择了测试>测试项目 这给了我解决方案下的另一个带有Test.cs文件的项目。我添加了以下内容: namespace TestProject1 { [TestClass] public class MainTest { //Project1.MainWindow mw = new Project1.MainWindow(); //not use

第一次尝试使用单元测试。我将完成以下步骤:

  • 右键单击要在visual studio中测试的项目的解决方案,然后单击“新建项目”。然后我选择了测试>测试项目

  • 这给了我解决方案下的另一个带有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());
        }
    }
    
    }

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

    现在,我的测试显示在测试视图中,但如果试图运行它,它将永远处于挂起状态。我尝试了另一个人的项目w/测试,它做了同样的事情。不知道我需要做什么。没有任何运气窥探谷歌

    编辑:当我尝试运行它时,这里有一些调试输出:

    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).
    
    线程“ExecutionUtilities.InvokeWithTimeout helper线程”Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter.AbortestTrun”(0x4748)已退出,代码为0(0x0)。
    id为“1bc08c40-ee7f-46e5-8689-8237cd3ffe4b”(0x2820)的测试“MakeDoubleDate”的线程“代理:适配器运行线程”(0x2820)已退出,代码为0(0x0)。
    id为“1bc08c40-ee7f-46e5-8689-8237cd3ffe4b”(0x1848)的测试“MakeDoubleDate”的线程“代理:状态执行线程”已退出,代码为0(0x0)。
    线程“代理:测试队列线程”(0x3ecc)已退出,代码为0(0x0)。
    W、 181608,2016/03/29,12:52:54.995,USERNAME\QTAgent32.exe,AgentObject.AgentStateWaiting:由于与控制器的连接丢失,正在继续清理数据采集器
    线程“代理:心跳线程”(0x4560)已退出,代码为0(0x0)。
    线程“”(0x2284)已退出,代码为0(0x0)。
    线程“”(0x4484)已退出,代码为0(0x0)。
    线程“”(0x43f4)已退出,代码为0(0x0)。
    线程“”(0x3a50)已退出,代码为0(0x0)。
    线程“”(0x4424)已退出,代码为0(0x0)。
    
    直到我退出VisualStudio


    编辑:看到了VisualStudio2010在没有service pack 1的情况下出现问题。结果我没有。现在更新,希望它能工作。

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


    从这个链接中得到了这样做的想法:

    通常挂起状态是在执行测试之前的构建期间。构建解决方案是否成功完成?是的!我尝试分别重建主项目和测试项目,以及整个解决方案,所有这些都成功了。这只是其中的一个测试。更新了我的帖子并提供了一些调试信息。主窗口成员是什么?在测试资源管理器中是否还有其他测试可见?