我有一些测试是使用Microsoft.VisualStudio.TestTools内置的。单元测试,但不能让它们运行。

我使用visual studio 2012终极版。

我有两个项目的解决方案;一个有测试,使用Microsoft.VisualStudio.TestTools。UnitTesting, [TestClass]在类之前,[TestMethod]在测试方法之前,并参考Microsoft.VisualStudio.QualityTools.UnitTestFramework(版本10.0.0.0,运行时版本v2.0.50727)。我已经尝试过。net框架3.5,4和4.5其他人给出了一个重定向错误。

我已经尝试构建解决方案和项目。测试资源管理器显示“构建解决方案以发现所有可用的测试”。单击“全部运行”可在解决方案中构建、发现和运行所有测试。

问题是:如何让visual studio找到测试?


我也试过遵循这个:http://msdn.microsoft.com/en-US/library/ms379625%28v=VS.80%29.aspx但没有成功:当我被要求右键单击并选择创建测试时,我被困在了开始的部分。没有创建测试。


我有这个测试(它编译,但不显示在测试资源管理器):

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace tests {
    [TestClass]
    public class SimpleTest {
        [TestMethod]
        public void Test() {
            Assert.AreEqual("a","a", "same");
        }
    }
}

我现在发现(见下面删除的答案),这是因为它在一个共享驱动器上,但我还不知道如何绕过它。(可能是关于安全设置的问题)。


当前回答

因为该项目是在一个共享驱动器上,原来的海报已经表明。VS.NET在加载和运行测试程序集之前需要信任网络位置。读一读这篇博客文章。

为了允许VS.NET加载网络共享的内容,需要将它们(共享)添加到可信位置。要将一个位置添加到完整的信任列表运行(显然根据您的环境需要进行修改):

 caspol -m -ag 1.2 -url file:///H:/* FullTrust

要验证或列出现有的受信任位置,执行以下命令:

 caspol -lg

其他回答

I found the best way to troubleshoot this issue is to create a .proj msbuild file and add your unit test projects which you hare having an issue into this file and execute the tests using the command line version of mstest. I found a small configuration issue in my app.config which only appeared when running the tests from mstest - otherwise the test project built just fine. Also you will find any indirect reference issues with this method as well. Once you can run the Unit test from the command line using mstest you can then do a clean solution, rebuild solution and your test should be discovered properly.

这更多的是为了帮助那些最终来到这里的人,而不是回答OP的问题:

尝试关闭和重新打开视觉工作室,为我做的把戏。

希望这能帮助到一些人。

我得到的错误:“初始化客户端代理失败:无法连接到vste .discoveryengine.exe。”

尝试以管理员身份运行Visual Studio。这对我很管用。

有另一篇Stack Overflow文章讨论了这个错误,同样的解决方案也适用于他们。问题是为什么这样做有效。

Visual Studio 2015 (v.14.....) -同样的问题

原因:NUnit和NUnit测试适配器版本不同 在我的情况下,我有最新版本的NUnit(3.5)和NUnit测试适配器,但测试适配器不是正确的。对于NUnit3或更高级别,必须使用NUnit3TestAdapter

解决方案: 卸载了“有问题的”NUnint测试适配器,并安装了UNit3TestAdapter v.3.5.0(现在最新的是3.6.0,但没有使用它,以保持它与NUnit相同)

重新构建解决方案测试后弹出:)

这个问题似乎有很多不同的解决方案,不妨加上我自己的:

关闭Visual Studio

重命名C:\Users\username\AppData\Local\Microsoft\ VisualStudio \ 12.0 \ ComponentModelCache 对ComponentModelCache.old

运行Visual Studio,组件缓存将被重建。