我有一些测试是使用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");
        }
    }
}

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


当前回答

看起来NUnit框架2.6.4不能很好地与NUnit测试适配器一起工作。在网站上,它提到测试适配器只适用于NUnit Framework 2.6.3。

这就是我的问题: 1. 我在VS2012中通过Nuget分别下载了NUnit和NUnit Test Adapter。不知怎的,NUnit更新到了2.6.4,突然我没有看到我的测试用例被列出。

Fix:

卸载Nuget和Nuget测试适配器 a.进入“Tools> Nuget > Nuget Pkg manager > Manage Nuget Pkg for Solution” b.列出已安装的包 c.单击“管理”。 d.取消你的项目 安装NUnit测试适配器,包括NUnit 2.6.3框架 清洁/重建解决方案 打开Test > Test Explorer >全部运行

我看到所有的测试用例

希望这能有所帮助

其他回答

这些都是很好的答案,但我知道还有一个原因;我只是碰巧碰到它。在我的一个测试中,我有一个ReSharper消息,表明我有一个未使用的私有类。这是一个我将在即将到来的测试中使用的类。这实际上导致我所有的测试都消失了。

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

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

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

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

对我来说是另一回事。我已经安装了一个包,然后卸载它,重新安装一个较早的版本。这在我的app.config中留下了残留的配置/runtime/ assemblybinding /dependencyIdentity重定向。我必须纠正它。 我通过查看输出窗口并在下拉菜单中选择“测试”来解决这个问题。错误信息就在那里。 这是一个痛苦……我希望它能帮助到其他人。

我在将我的解决方案从Microsoft Visual Studio 2012 Express for Web升级到Microsoft Visual Studio 2013时遇到了这个问题。

我在2012年创建了一个单元测试项目,2013年打开后,单元测试项目在测试资源管理器中不会显示任何测试。每次我试图运行或调试测试时,它都会失败,在输出窗口中显示以下内容:

    Failed to initialize client proxy: 
    could not connect to vstest.discoveryengine.x86.exe

我还注意到,在调试测试时,它正在启动Visual Studio 2012的一个实例。这让我意识到单元测试项目仍然引用了2012年。查看测试项目参考,我意识到它针对这个版本的Visual Studio的错误Microsoft Visual Studio单元测试框架DLL:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

我把版本号从11.0改为12.0:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

我重新构建了所有的测试,这解决了这个问题——所有的测试都在测试资源管理器中找到了,现在所有的测试都找到了,并且运行得很好。

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.