【发布时间】:2016-03-29 16:39:46
【问题描述】:
第一次尝试使用单元测试。我将完成我的步骤:
右键单击我想在 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 的引用。
现在,我的测试显示在测试视图中,但尝试运行它只是永远停留在挂起状态。我尝试了另一个人的带有测试的项目,它做了同样的事情。不知道我需要做什么。没有任何运气窥探谷歌。
编辑:这是我尝试运行时的一些调试输出:
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 在没有服务包 1 时出现问题的信息。结果我没有。正在更新中,希望能成功。
【问题讨论】:
-
通常挂起状态是在构建期间执行测试之前。构建解决方案是否成功完成?
-
是的!我尝试分别重建主项目和测试项目,以及整个解决方案,所有这些都成功了。现在只是其中的一项测试。
-
用一些调试信息更新了我的帖子。
-
什么是 MainWindow 成员?
-
测试资源管理器中是否还有其他测试可见?
标签: c# wpf unit-testing