c# - 我的单元测试总是挂起

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

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

现在,我的测试显示在测试 View 中,但尝试运行它时它永远停留在挂起状态。我尝试了另一个人的带有测试的项目,它做了同样的事情。不确定我需要做什么。没有任何运气在谷歌周围窥探。

编辑:这是我尝试运行它时的一些调试输出:

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。

编辑:看到一些关于 visual studio 2010 的问题 w/o service pack 1。结果我没有。正在更新,希望它有效。

最佳答案

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

从这个链接得到这样做的想法:VS2010 Unit test “Pending” and the test cannot be completed

关于c# - 我的单元测试总是挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36290174/

相关文章:

c# - SignalR 连续消息传递

c# - 使用 C# 的数学向量在堆栈上还是堆上更快?

c# - 如何避免 View 模型的冗余属性

javascript - Jest - 如何检查一个函数是否被另一个函数调用

java - 使用 Maven 跳过 Jhipster 中的 Java 测试进行构建

c# - 模型关系导致 Swagger/端点出现问题

c# - 在C#中嵌入一个Lua交互提示窗口

c# - 如何将参数发送到 ICommand 的 Execute 方法

c# - 使用枚举标志位的 WPF 基于权限的授权

reactjs - 我如何 Jest 测试这个功能?