简体   繁体   English

为什么 Visual Studio 2012 找不到我的测试?

[英]Why does visual studio 2012 not find my tests?

I have some tests that use the built in Microsoft.VisualStudio.TestTools.UnitTesting , but can not get them to run.我有一些使用内置Microsoft.VisualStudio.TestTools.UnitTesting测试,但无法让它们运行。

I am using visual studio 2012 ultimate.我正在使用 Visual Studio 2012 Ultimate。

I have a solution of two projects;我有两个项目的解决方案; One has tests, using Microsoft.VisualStudio.TestTools.UnitTesting , [TestClass] before the class, [TestMethod] before the test methods and reference Microsoft.VisualStudio.QualityTools.UnitTestFramework (version 10.0.0.0, runtime version v2.0.50727).一个有测试, using Microsoft.VisualStudio.TestTools.UnitTesting ,在类之前using Microsoft.VisualStudio.TestTools.UnitTesting [TestClass] ,在测试方法之前使用[TestMethod]并参考Microsoft.VisualStudio.QualityTools.UnitTestFramework (版本 10.0.0.0,运行时版本 v2.0.50727)。 I have tried dot-net framework 3.5, 4 and 4.5 others give a re-targeting error.我已经尝试过 dot-net framework 3.5、4 和 4.5 其他人给出了重新定位错误。

I have tried to build the solution and project.我试图构建解决方案和项目。 Test explorer has the message `Build your solution to discover all available tests.测试资源管理器显示消息`构建您的解决方案以发现所有可用测试。 Click "run all" to build, discover, and run all tests in your solution.单击“全部运行”以构建、发现和运行解决方案中的所有测试。

So the question is: How to I get visual studio to find the tests?所以问题是:如何让 Visual Studio 找到测试?


Have also tried to follow this: http://msdn.microsoft.com/en-US/library/ms379625%28v=VS.80%29.aspx but with no success: I get stuck in section getting started, when asked to right click and select create tests .也曾尝试遵循这个: http : //msdn.microsoft.com/en-US/library/ms379625%28v=VS.80%29.aspx但没有成功:当被要求时,我被困在开始部分右键单击并选择create tests There is no create tests .没有create tests


I have this test(it compiles, but does not show up in test explorer):我有这个测试(它编译,但没有出现在测试资源管理器中):

using Microsoft.VisualStudio.TestTools.UnitTesting;

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

I have now discovered (see deleted answer below) that it is because it is on a shared drive, but I don't as yet know how to get around it.我现在发现(请参阅下面已删除的答案)这是因为它位于共享驱动器上,但我还不知道如何解决它。 (something about the security setting maybe). (可能与安全设置有关)。

I had same symptoms, but under different circumstances. 我有相同的症状,但在不同的情况下。

I had to add one additional step to Peter Lamberg's solution — Clean your solution/project. 我不得不为Peter Lamberg的解决方案添加一个额外的步骤 - 清理您的解决方案/项目。

My unittest project targets x64. 我的unittest项目针对x64。 When I created the project it was originally targeting x86. 当我创建项目时,它最初的目标是x86。

After switching to x64 all my unit tests disappeared. 切换到x64后,我的所有单元测试都消失了。

I had to go to the Test Menu -> Test Setting -Default Processor Architecture -> x64. 我不得不去测试菜单 - >测试设置 - 默认处理器架构 - > x64。

They still didn't show up. 他们仍然没有露面。

Did a build. 做了一个。

Still didn't show up. 仍然没有出现。

Finally did a Clean 最后做了一个清洁

Then they showed up. 然后他们出现了。

I find Clean Solution and Clean to be quite useful at getting the solutions to play ball when setting have changed. 我发现清洁解决方案和清洁在设置更改时获得解决方案非常有用。 Sometimes I have to go to the extreme and delete the obj and bin directories and do a rebuild. 有时我必须走极端并删除objbin目录并进行重建。

Please add the keyword public to your class definition. 请将关键字public添加到您的类定义中。 Your test class is currently not visible outside its own assembly. 您的测试类目前在其自己的程序集之外不可见。

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

This sometimes works. 这有时会奏效。

Check that the processor architecture under Test menu matches the one you use to build the solution. 检查“测试”菜单下的处理器体系结构是否与用于构建解决方案的处理器体系结

Test -> Test Settings -> Default Processor Architecture -> x86 / x64 测试 - >测试设置 - >默认处理器架构 - > x86 / x64

As mentioned in other posts, make sure you have the Test Explorer window open. 如其他帖子中所述,请确保打开“测试资源管理器”窗口。 Test -> Windows -> Test Explorer 测试 - > Windows - >测试资源管理器

Then rebuilding the project with the tests should make the tests appear in Test Explorer. 然后使用测试重建项目应该使测试显示在测试资源管理器中。

Edit: As Ourjamie pointed out below, doing a clean build may also help. 编辑:正如Ourjamie在下面指出的那样,做一个干净的构建也可能有所帮助。 In addition to that, here is one more thing I encountered: 除此之外,还有一件事我遇到了:

The "Build" checkbox was unticked in Configuration Manager for a new test project I had created under the solution. 在Configuration Manager中未选中“构建”复选框,以获取我在解决方案下创建的新测试项目。

Go to Build -> Configuration Manager. 转到Build - > Configuration Manager。 Make sure your test project has build checkbox checked for all solution configurations and solution platforms. 确保为所有解决方案配置和解决方案平台检查了测试项目是否已构建复选框。

I have Visual Studio 2012 and i couldn't see the Tests in Test Explorer, 我有Visual Studio 2012,我在Test Explorer中看不到测试,

So I installed the following: NUnit Test Adapter 所以我安装了以下内容: NUnit Test Adapter

That fixed the issue for me ! 这解决了我的问题!

In my recent experience all of the above did not work. 根据我最近的经验,以上所有都不起作用。 My test method 我的测试方法

public async void ListCaseReplace() { ... }

was not showing up but compiling fine. 没有出现,但编译得很好。 When I removed the async keyword the test the showed up in the Test Explorer. 当我删除了async关键字时,测试资源管理器中显示的测试结果。 This is bacause async void is a 'fire-and-forget' method. 这是因为async void是一种“即发即忘”的方法。 Make the method async Task and you will get your test back! 使方法成为async Task ,您将得到您的测试!

In addition, not having the Test project's configuration set to "Build" will also prevent tests from showing up. 此外,没有将Test项目的配置设置为“Build”也会阻止测试显示。 Configuration Manager > Check your Test to build. Configuration Manager>检查您的测试以构建。

Since the project is on a shared drive as the original poster have indicated. 由于该项目是在原始海报所示的共享驱动器上。 VS.NET needs to trust network location before it will load and run your test assemblies. VS.NET在加载和运行测试程序集之前需要信任网络位置。 Have a read of this blog post . 阅读这篇博客文章

To allow VS.NET to load things of a network share one needs to add them (shares) to trusted locations. 要允许VS.NET加载网络共享的内容,需要将它们(共享)添加到受信任位置。 To add a location to a full trust list run (obviously amend as required for you environment): 要将位置添加到完整信任列表运行(显然根据您的环境进行修改):

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

To verify or list existing trusted locations run: 要验证或列出运行的现有受信任位置:

 caspol -lg

A problem I've found is that tests don't get found in the Test Explorer (nothing shows up) if the solution is running off a network drive / network location / shared drive 我发现的一个问题是,如果解决方案在网络驱动器/网络位置/共享驱动器上运行,则在测试资源管理器中找不到测试(没有显示)

You can fix this by adding an environment variable. 您可以通过添加环境变量来解决此问题。

COMPLUS_LoadFromRemoteSources and set its value to 1 COMPLUS_LoadFromRemoteSources并将其值设置为1

I was getting the error: "Failed to initialize client proxy: could not connect to vstest.discoveryengine.exe." 我收到错误: "Failed to initialize client proxy: could not connect to vstest.discoveryengine.exe."

Try to run Visual Studio as Administrator. 尝试以管理员身份运行Visual Studio。 That worked for me. 这对我有用。

There is another Stack Overflow post discussing this error , and the same solution works for them. 还有另一个Stack Overflow帖子讨论了这个错误 ,同样的解决方案适用于他们。 The question remains why this works. 这个问题仍然存在。

I had the same problem.. In my case it was caused by a private property TestContext . 我有同样的问题..在我的情况下,它是由私有属性 TestContext引起的。

Changing it to the following helped: 将其更改为以下内容有助于:

public TestContext TestContext
{
    get;
    set;
}

After cleaning and building the solution (as described in @Ourjamie 's answer), the test methods in the affected test class were available in the Test Explorer. 清理并构建解决方案后(如@Ourjamie的回答中所述),受测试的测试类中的测试方法可在测试资源管理器中找到。

I ran into the same issue while trying to open the solution on a network share. 尝试在网络共享上打开解决方案时遇到了同样的问题。 No unit test would be detected by Test Explorer in this case. 在这种情况下,测试资源管理器不会检测到任何单元测试。 The solution turns out to be: 解决方案原来是:

Control Panel -> Internet Options -> "Security" Tab -> Click "Intranet" and add the server IP address or host name holding the network share to the "Sites" list. 控制面板 - > Internet选项 - >“安全”选项卡 - >单击“内部网”,将保存网络共享的服务器IP地址或主机名添加到“站点”列表中。

After doing this, I recompiled the solution and now tests appeared. 在这之后,我重新编译了解决方案,现在测试出现了。 This should be quite similar to the answer made by @BigT. 这应该与@BigT的答案非常相似。

Quick check list for solving some common test problems. 用于解决一些常见测试问题的快速检查清单。 Make sure that: 确保:

  1. Test class and test methods are public 测试类和测试方法是public
  2. Test class has [TestClass] attribute 测试类具有[TestClass]属性
  3. Test methods have [TestMethod] attribute 测试方法具有[TestMethod]属性

If this does not help, try cleaning, rebuilding solution and restarting Visual Studio. 如果这没有帮助,请尝试清理,重建解决方案并重新启动Visual Studio。

I sometimes get the same symptoms. 我有时会得到相同的症状。

What I did is: 我做的是:
1. Closed the Test Explorer window 1.关闭Test Explorer窗口
2. Cleaned the solution 2.清理解决方案
3. Rebuild the solution 3.重建解决方案
4. Relaunched Test Explorer window from Test -> Windows -> Test Explorer. 4.从Test - > Windows - > Test Explorer重新启动Test Explorer窗口。

And I got my test in Test Explorer window. 我在Test Explorer窗口中进行了测试。

From menu bar on top... 从顶部的菜单栏...

Test -> Run -> All Tests 测试 - >运行 - >所有测试

You may also view all tests from Test Explorer (Test -> Windows -> Test Explorer) 您还可以从Test Explorer查看所有测试(测试 - > Windows - >测试资源管理器)

Further with VS 2012, if you miss out anything try searching it using Quick Launch bar on top right (Ctrl + Q) "Test" 进一步使用VS 2012,如果您遗漏了任何内容,请尝试使用右上角的快速启动栏进行搜索(Ctrl + Q)“测试”

Hope this helps. 希望这可以帮助。

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. 我发现解决此问题的最佳方法是创建.proj msbuild文件,并将您遇到问题的单元测试项目添加到此文件中,并使用命令行版本的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. 我在app.config中发现了一个小配置问题,只有在从mstest运行测试时才会出现 - 否则测试项目构建得很好。 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. 一旦您可以使用mstest从命令行运行Unit测试,您就可以执行一个干净的解决方案,重建解决方案并正确发现您的测试。

In My case it was something else. 在我的情况下,它是另一回事。 I had installed a package and then uninstall it and reinstall an earlier version. 我安装了一个软件包然后将其卸载并重新安装了早期版本。 That left a residual configuration/runtime/asssemblyBinding/dependencyIdentity redirecting in my app.config. 这留下了我的app.config中的残留configuration/runtime/asssemblyBinding/dependencyIdentity重定向。 I had to correct it. 我不得不纠正它。 I figured it out by looking at the Output window and selecting " Tests " in the drop down. 我通过查看“ Output窗口并在下拉列表中选择“ Tests ”来计算出来。 The error message was there. 错误消息在那里。 This was a pain... I hope it helps someone else. 这是一种痛苦......我希望它可以帮助别人。

This is more to help people who end up here rather than answer the OP's question: 这更多的是帮助那些最终到达这里的人而不是回答OP的问题:

Try closing and re-opening visual studio, did the trick for me. 尝试关闭并重新打开visual studio,为我做了诀窍。

Hope this helps someone. 希望这有助于某人。

I know this is an older question but with Visual Studio 2015 I was having issues where my newly created test class was not being recognized. 我知道这是一个较旧的问题,但在Visual Studio 2015中,我遇到了新创建的测试类未被识别的问题。 Tried everything. 尝试了一切。 What ended up being the issue was that the class was not "included in the project". 最终成为问题的是该课程没有“包含在项目中”。 I only found this on restarting Visual Studio and noticing that my test class was not there. 我只是在重新启动Visual Studio时发现了这一点,并注意到我的测试类不在那里。 Upon showing hidden files, I saw it, as well as other classes I had written, were not included. 在显示隐藏文件时,我看到它以及我编写的其他类都没有包括在内。 Hope that helps 希望有所帮助

I was experiencing this issue many times when I try to build the solution in a different PC. 当我尝试在不同的PC上构建解决方案时,我经常遇到这个问题。

I am using NUnit and Specflow as well. 我也在使用NUnit和Specflow。 By default My test project targets X86 But I have to change this to X64. 默认情况下,我的测试项目以X86为目标,但我必须将其更改为X64。 Steps are 1. Test Menu -> Test Setting -Default Processor Architecture -> x64. 步骤是1.测试菜单 - >测试设置 - 默认处理器架构 - > x64。 2. Clean Build 3. Build 4. If still tests didn't show up. 2.清理构建3.构建4.如果仍然没有显示测试。 5. Go to Tools  Extensions and Updates Then Install NUnit and Specflow libraries 6. Clean Build 7. Build 5.转到工具扩展和更新然后安装NUnit和Specflow库6.清理构建7.构建

Then usually test will showed up in Test Editor. 然后通常测试将出现在测试编辑器中。

I've updated VS 2012 to the Latest Update . 我已将VS 2012更新到最新更新。 ie visual studio update 3. That fixed the issue for me. 即视觉工作室更新3.这为我解决了问题。

For Me the solution was just a little bit less complicated. 对我而言,解决方案稍微复杂一点。

I had just brought an existing solution on to my machine (cloned from gitHub) and we do not track the auto-generated .cs files that Visual Studio created. 我刚刚将一个现有的解决方案带到我的机器上(从gitHub克隆),我们不跟踪Visual Studio创建的自动生成的.cs文件。 (For each feature file there is a .cs file with the same name) (对于每个功能文件,都有一个同名的.cs文件)

Opening the solution without having the associated .cs files actually allow me to navigate to the bound methods, so it appeared as if specflow was wired up properly, but I was not able to view the test names in the Test Explorer. 在没有关联的.cs文件的情况下打开解决方案实际上允许我导航到绑定的方法,因此看起来好像specflow已正确连接,但我无法在测试资源管理器中查看测试名称。

For this problem simply excluding the feature files from the project and then re-including them, forced VS to regenerate these auto generated codebehind files. 对于此问题,只需从项目中排除功能文件,然后重新包含它们,强制VS重新生成这些自动生成的代码隐藏文件。

After that, I was able to view the tests in the test explorer. 之后,我能够在测试资源管理器中查看测试。

I had this problem when upgrading my solution from Microsoft Visual Studio 2012 Express for Web to Microsoft Visual Studio 2013. 将我的解决方案从Microsoft Visual Studio 2012 Express for Web升级到Microsoft Visual Studio 2013时出现此问题。

I had created a Unit Tests project in 2012, and after opening in 2013 the Unit Test project wouldn't show any tests in the tests explorer. 我在2012年创建了一个单元测试项目,并在2013年开放后,单元测试项目不会在测试资源管理器中显示任何测试。 Everytime I tried to run or debug tests it failed, saying the following in the output window: 每次我尝试运行或调试测试时都失败了,在输出窗口中说出以下内容:

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

I also noticed that on debugging the tests, it was launching an instance of Visual Studio 2012. This clued me into the fact that the Unit Tests project was still referencing 2012. Looking at the test project reference I realised it was targeting the wrong Microsoft Visual Studio Unit Test Framework DLL for this version of Visual Studio: 我还注意到,在调试测试时,它正在启动一个Visual Studio 2012实例。这让我觉得单元测试项目仍在引用2012.看看测试项目参考,我意识到它的目标是错误的Microsoft Visual此版本的Visual Studio的Studio Unit Test Framework DLL:

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

I changed the version number from 11.0 to 12.0: 我将版本号从11.0更改为12.0:

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

I rebuilt all and this fixed the issue - all tests were found in the Test Explorer and now all tests are found and running perfectly. 我重建了所有这一切并解决了这个问题 - 所有测试都在测试资源管理器中找到,现在所有的测试都找到并且运行得很完美。

Check that your test project is not set to Delay sign only in your project properties -> Signing. 检查您的测试项目没有设置在您的项目属性,以延缓标志 - >签名。 If it is, deselect it and do a clean rebuild. 如果是,请取消选择它并进行干净的重建。

I hit the same problem while trying to open the solution on a network share in VS2013 Ultimate. 尝试在VS2013 Ultimate中的网络共享上打开解决方案时遇到了同样的问题。

I corrected the problem by turning on 我打开后纠正了这个问题

Control Panel -> Internet Options -> "Security" Tab -> Click "Local intranet", click on sites and make sure "Automatically detect intranet network" is ticked. 控制面板 - > Internet选项 - >“安全”选项卡 - >单击“本地Intranet”,单击站点并确保勾选“自动检测Intranet网络”。

These are all great answers, but there is one more reason that I know of; 这些都是很好的答案,但还有一个我知道的原因; I just ran into it. 我刚碰到它。 In one of my tests I had a ReSharper message indicating that I had an unused private class. 在我的一个测试中,我有一条ReSharper消息,表明我有一个未使用的私有类。 It was a class I'm going to use in an upcoming test. 这是我将要在即将进行的测试中使用的课程。 This actually caused all of my tests to disappear. 这实际上导致我的所有测试都消失了。

Check referenced assemblies for any assemblies that may have "Copy Local" set to "False". 检查引用的程序集,查看可能将“Copy Local”设置为“False”的任何程序集。

If your test project builds to it's own folder (bin/Debug for example) and the project depends on another assembly and one of those assemblies in the References list is marked Copy Local = "False", the assembly cannot load due to missing dependencies and your tests will not load after a build. 如果您的测试项目构建到它自己的文件夹(例如bin / Debug)并且项目依赖于另一个程序集,并且References列表中的一个程序集被标记为Copy Local =“False”,则由于缺少依赖项而无法加载程序集构建后,您的测试不会加载。

None of the solutions here helped me. 这里的解决方案都没有帮助我。 The tests wouldn't be discovered for one solution whereas another solution referencing the same projects worked fine. 对于一个解决方案不会发现测试,而引用相同项目的另一个解决方案工作正常。 I finally solved this by deleting the solutionname.v12.suo file. 我终于通过删除solutionname.v12.suo文件解决了这个问题。

It looks like NUnit Framework 2.6.4 does not work well with NUnit Test Adapter. 看起来NUnit Framework 2.6.4与NUnit Test Adapter不兼容。 In the website it mentions the test adapter will only work with NUnit Framework 2.6.3. 在网站上它提到测试适配器只能与NUnit Framework 2.6.3一起使用。

This was my problem: 1. I had downloaded NUnit and NUnit Test Adapter separately through Nuget in the VS2012. 这是我的问题:1。我在VS2012中通过Nuget分别下载了NUnit和NUnit Test Adapter。 Somehow NUnit got updated to 2.6.4 Suddenly i did not see my test cases listed. NUnit以某种方式更新到2.6.4突然间我没有看到列出的测试用例。

Fix: 固定:

  1. Uninstall Nuget and Nuget Test adapter 卸载Nuget和Nuget Test适配器

    a. 一个。 Go to Tools> Nuget > Nuget Pkg manager > Manage Nuget Pkg for Solution 转到工具> Nuget> Nuget Pkg管理器>管理Nuget Pkg for Solution

    b. List installed packages 列出已安装的包

    c. C。 Click manage 点击管理

    d. d。 Un-check your projects 取消检查您的项目

  2. Install NUnit Test Adapter including NUnit 2.6.3 Framework 安装NUnit测试适配器,包括NUnit 2.6.3 Framework

  3. Clean/Rebuild solution 清洁/重建解决方案

  4. Open Test > Test Explorer > Run All 打开测试>测试资源管理器>全部运行

I see all the test cases 我看到了所有的测试用例

Hope this helps 希望这可以帮助

I had same issue, but a bit different. 我有同样的问题,但有点不同。

I was using visual studio 2012. For some reason, only the tests of the initial generated file was running. 我使用的是visual studio 2012.由于某种原因,只有初始生成文件的测试正在运行。 But tests in another file were not running. 但是另一个文件中的测试没有运行。 Tried out different solutions posted here, did not work. 试过这里发布的不同解决方案,没有用。

Finally I figured out that I had a private method in the test class which was the first method inside the class. 最后我发现我在测试类中有一个私有方法,这是该类中的第一个方法。 I just moved the private method after a test method; 我只是测试方法之后移动了私有方法; so now, a method with [TestMethod] attribute is the first method inside the class. 所以现在, [TestMethod]属性的方法是类中的第一个方法。 Strange, but now it works. 奇怪,但现在它的工作原理。

Hope this helps someone someday. 希望有一天能帮助某人。

Tests do not like async methods. 测试不喜欢异步方法。 Eg: 例如:

    [TestMethod]
    public async void TestMethod1()
    {
        TestLib oLib = new TestLib();
        var bTest = await oLib.Authenticate();

    }

After doing this: 这样做之后:

    [TestMethod]
    public void TestAuth()
    {
        TestMethod1();
    }

    public async void TestMethod1()
    {
        TestLib oLib = new TestLib();
        var bTest = await oLib.Authenticate();

    }

It saw the test. 它看到了测试。

Adding my answer as this is the top result on Google for this. 添加我的答案,因为这是谷歌的最佳结果。

I'm using Visual Studio 2015 and (unknowingly - I just ran Install-Package NUnit ) installed the NUnit3 package NuGet to my test project. 我正在使用Visual Studio 2015并且(在不知情的情况下 - 我刚刚运行Install-Package NUnit )将NUnit3包NuGet安装到我的测试项目中。 I already had the NUnit Test Adapter extension installed, and my tests were still not showing up. 我已经安装了NUnit Test Adapter扩展,但我的测试仍未显示。

Installing the NUnit3 Test Adapter through Tools > Extensions and Updates fixed this for me. 通过工具>扩展和更新安装NUnit3测试适配器为我解决了这个问题。

I tried all the above and still my Visual Studio 2012 did not show up the tests.我尝试了上述所有方法,但我的 Visual Studio 2012 仍然没有显示测试。 In the end I went to a test class and found it had a RootNamespace.FolderName and I removed the .FolderName to put the class in the root namespace and bingo all the tests came back!最后我去了一个测试类,发现它有一个 RootNamespace.FolderName 并且我删除了 .FolderName 将类放在根命名空间中,宾果游戏所有测试都回来了!

Cannot understand why it was working fine with the original namespace till the other day.直到有一天,无法理解为什么它可以与原始命名空间一起正常工作。

I copy-pasted the method declaration, which included an input string parameter.我复制粘贴了方法声明,其中包括一个输入字符串参数。 Forgot to delete the input parameter.忘记删除输入参数。

  public void ExtractValueFromLineTest(string input) {}//test not discovered because of the string input param

This one just bit me.这个只是咬了我一口。 I added a test to my project, but could not get it to show up in Test Explorer.我向我的项目添加了一个测试,但无法让它显示在测试资源管理器中。 My old tests all showed up.我的旧测试都出现了。 Finally, I realized I was only viewing a specific playlist, and I had not added the new test to the playlist.最后,我意识到我只是在查看特定的播放列表,而没有将新测试添加到播放列表中。 If you are using playlists, select "All Tests" and see if VS finds your tests and displays them in Test Explorer.如果您使用播放列表,请选择“所有测试”并查看 VS 是否找到您的测试并将其显示在测试资源管理器中。 Then you can add them to the desired playlist, too.然后您也可以将它们添加到所需的播放列表中。

Visual Studio Professional 2012, update 4 here. Visual Studio Professional 2012,在这里更新 4。 Having Interop function definitions (DllImport/extern) in the same project as test classes confused Test Explorer.在与测试类相同的项目中具有互操作函数定义(DllImport/extern)会使测试资源管理器感到困惑。 Moving Interop into a separate project, resolved the issue.将 Interop 移动到一个单独的项目中,解决了这个问题。

I encountered the same problem in VS2013 Ultimate.我在 VS2013 Ultimate 中遇到了同样的问题。 My problem was that I was creating a Windows Service and forgot to uninstall it.我的问题是我正在创建一个 Windows 服务并且忘记卸载它。 So the Service was running and VS couldn't access one of the DLLs which caused that the whole test suite wasn't loaded at all.所以服务正在运行,VS 无法访问导致整个测试套件根本没有加载的 DLL 之一。

Here's another one to add to the list based on user error/stupidity.... I tried various answers from this question and then realised my test project was unticked in the Configuration Manager (Build menu, Configuration Manager) so it wasn't being built >.<这是另一个基于用户错误/愚蠢添加到列表中的...建>.<

Posting this in the hope it'll save someone wasting an hour or two as I just did!发布此内容是希望它可以像我一样节省某人浪费一两个小时的时间!

I was experiencing the same issue in Visual Studio 2013 Update 4 on Windows 7 SP1 x64 using a test project targeting the "Any CPU" platform configuration.我在使用针对“任何 CPU”平台配置的测试项目的 Windows 7 SP1 x64 上的 Visual Studio 2013 Update 4 中遇到了同样的问题。

The problem was that the test project was actually named "Tests" and would disappear the second time the project was (re)built.问题是测试项目实际上被命名为“Tests”,并且会在第二次(重新)构建项目时消失。

After I renamed the project to "MyProject.Tests" for example, the tests no longer disappear.例如,在我将项目重命名为“MyProject.Tests”后,测试不再消失。

One issue I've run into repetitively is not running Visual Studio (explicitly) as Administrator on Windows 8+.我反复遇到的一个问题是没有在 Windows 8+ 上以管理员身份运行 Visual Studio(明确地)。 I tried several of the suggestions listed, but they did not get the unit tests to appear until I ran VS 2013 as Administrator (even though my shortcut is set to open VS that way, either opening the solution file or sometimes clicking the shortcut it doesn't actually open as admin).我尝试了列出的几个建议,但是直到我以管理员身份运行 VS 2013 之后,它们才显示单元测试(即使我的快捷方式设置为以这种方式打开 VS,无论是打开解决方案文件还是有时单击快捷方式它都没有'实际上不是以管理员身份打开)。

Since none of these answers deal with the cause I encountered, for this problem, I will add my answer here as well.由于这些答案都没有涉及我遇到的原因,对于这个问题,我也会在这里添加我的答案。

In my case, it was a copy pasting code problem.就我而言,这是一个复制粘贴代码问题。 We had a TestProjectA where there are specific type of tests that we want to pull out to its own test project - TestProjectB .我们有一个TestProjectA ,其中有我们想要提取到它自己的测试项目 - TestProjectB特定类型的测试。 The problem now was that, while tests in TestProjectA continue to show up just fine, the tests in the new TestProjectB aren't showing up in VS Test Explorer - unless you specifically build TestProjectB or manually right click on a test there and run it.现在的问题是,虽然TestProjectA测试继续正常显示,但新TestProjectB中的测试未显示在 VS 测试资源管理器中 - 除非您专门构建TestProjectB或手动右键单击那里的测试并运行它。

The cause was that in copy pasting the code over, some namespaces didn't get updated:原因是在复制粘贴代码时,某些命名空间没有更新:

  • There is a TestMethodA() in TestClassA in namespace TestProjectA.ModuleA with filepath \\TestProjectA\\TestClassA.cs在命名空间TestProjectA.ModuleA中的TestClassA中有一个TestMethodA() ,文件路径为\\TestProjectA\\TestClassA.cs
  • As well as a TestMethodA() in TestClassB in namespace TestProjectA.ModuleA with filepath \\TestProjectB\\TestClassB.cs以及具有文件路径\\TestProjectB\\TestClassB.cs命名空间TestProjectA.ModuleATestClassB中的TestMethodA()

So visual Studio prints out a message in Output window that the TestId for these two are the same, and proceeds to show TestProjectA and not TestProjectB in Test Explorer due to the TestId clashing between the two projects.因此,visual Studio 在输出窗口中打印出一条消息,表明这两个项目的 TestId 相同,并且由于两个项目之间的 TestId 冲突,因此继续在测试资源管理器中显示TestProjectA而不是TestProjectB Correcting the namespace to TestProjectB.ModuleB for \\TestProjectB\\TestClassB.cs fixed the issue.更正命名空间TestProjectB.ModuleB\\TestProjectB\\TestClassB.cs固定的问题。

This problem seems to have so many different solutions may as well add my own:这个问题好像有这么多不同的解决方案不妨加上我自己的:

Close Visual Studio关闭 Visual Studio

Rename C:\\Users\\username\\AppData\\Local\\Microsoft\\VisualStudio\\12.0\\ComponentModelCache to ComponentModelCache.old将 C:\\Users\\username\\AppData\\Local\\Microsoft\\VisualStudio\\12.0\\ComponentModelCache 重命名为 ComponentModelCache.old

Run Visual Studio and the component cache will be rebuilt.运行 Visual Studio,将重建组件缓存。

Another issue that may prevent tests from being discovered, usually with a message in the Tests output window like:另一个可能会阻止发现测试的问题,通常在“测试”输出窗口中显示如下消息:

Failed to configure settings for runsettings plugin 'VSTest Run Configuration' as it threw following exception:
'An error occurred while parsing EntityName. Line 1, position 8.'
Please contact the plugin author.

This can be caused by having characters in your path or file names that would need escaping to be parsed as xml.这可能是由于路径或文件名中包含需要转义才能解析为 xml 的字符造成的。 Specifically the & character, as < and > are not allowed in directory or file names.特别是&字符,因为<>不允许出现在目录或文件名中。 This causes the test discovery to fall over and not identify the tests, but I could still run the tests by hand using Resharper by clicking in the margin.这会导致测试发现失败并且无法识别测试,但我仍然可以通过单击边距使用 Resharper 手动运行测试。

After googling "visual studio can't see tests" it brought me here, so I thought I'd share my problem.在谷歌搜索“视觉工作室无法看到测试”之后,它把我带到了这里,所以我想我会分享我的问题。 I could build my solution, and the tests existed, but I could not see them!我可以构建我的解决方案,并且测试存在,但我看不到它们! It turns our it was a quirk of the IDE, that caused the problem.事实证明,这是 IDE 的一个怪癖,导致了问题。 See image below for an explanation and fix:有关解释和修复,请参见下图:

在此处输入图片说明

The simplest thing you can do is, just drag and drop those files from the File Explorer to the Test project.您可以做的最简单的事情是,只需将这些文件从文件资源管理器拖放到测试项目中即可。 Build the project again, and you are good to go!再次构建项目,一切顺利!

OR或者

Open the .csproj file of your Test project in a text editor and manually include the file name to compile.在文本编辑器中打开测试项目的.csproj文件并手动包含要编译的文件名。 Search for the Compile tag in the file and add your file which you want to run.在文件中搜索Compile标记并添加要运行的文件。

<ItemGroup>
    <Compile Include="TestSettings.cs" />
    <Compile Include="TestLibrary.cs" />
    <Compile Include="UnitTest1.cs" />
</ItemGroup>

Add the Compile tag for your file and save it.为您的文件添加 Compile 标记并保存它。 Now run the tests.现在运行测试。 Your file with unit test will be detected and run.将检测并运行带有单元测试的文件。

The problem was that the test runner, is configured to not run tests from a remote drive.问题是测试运行器被配置为不从远程驱动器运行测试。 When I copied the project to a local drive it worked fine, but I needed it on a shared drive (can not remember why).当我将项目复制到本地驱动器时,它运行良好,但我需要在共享驱动器上使用它(不记得为什么)。

I read that it can be configured to work from a shared drive, but never got to do it as by the time I discovered the solution I had switched to MonoDevelop on Debian.我读到它可以配置为从共享驱动器工作,但从来没有这样做,因为当我发现解决方案时,我已经在 Debian 上切换到 MonoDevelop。

I read all the existing answers and found that my (xUnit) tests weren't being discovered because I had removed 'unused' references and more specifically, xunit.execution.desktop .我阅读了所有现有的答案,发现我的 (xUnit) 测试没有被发现,因为我已经删除了“未使用”的引用,更具体地说,是xunit.execution.desktop Re-installing the xUnit package fixed the issue in my case.重新安装 xUnit 包解决了我的问题。

Visual Studio 2015 (v.14.....) - same problem here Visual Studio 2015 (v.14 .....) - 同样的问题在这里

Cause: Different versions of NUnit and NUnit Test Adapter In my case I had the latest versions of both NUnit (3.5) and NUnit Test Adapter but the Test Adapter was not the right one.原因:不同版本的 NUnit 和 NUnit 测试适配器 就我而言,我拥有最新版本的 NUnit (3.5) 和 NUnit 测试适配器,但测试适配器不是正确的。 For NUnit 3 and higher there is a NUnit3TestAdapter that must be used对于 NUnit 3 及更高版本,必须使用 NUnit3TestAdapter

Solution: Uninstalled the "faulty" NUnint Test Adapter and installed the UNit3TestAdapter v.3.5.0 (the latest now is 3.6.0 but didn't use it in order to keep it same as NUnit)解决方案:卸载“有故障”的 NUnint 测试适配器并安装 UNit3TestAdapter v.3.5.0(现在最新的是 3.6.0 但没有使用它以保持与 NUnit 相同)

After Rebuild of the Solution Tests poped up :)重建解决方案测试后弹出:)

In my case, I had 3 test projects, created with Visual Studio 2017 (but I think it doesn't matter), and only two of them were discovered by the Test Explorer.就我而言,我有 3 个使用 Visual Studio 2017 创建的测试项目(但我认为这无关紧要),而测试资源管理器仅发现了其中两个。 I realized that the third project had a different version of the Microsoft.VisualStudio.QualityTools.UnitTestFramework dll.我意识到第三个项目有一个不同版本的Microsoft.VisualStudio.QualityTools.UnitTestFramework dll。 I updated it in the NuGet Manager and the tests appeared.我在 NuGet 管理器中更新了它,测试出现了。

We were using xunit and solution worked for me and the team was deleting the folder %TEMP%\\VisualStudioTestExplorerExtensions我们正在使用 xunit 并且解决方案对我有用,团队正在删除文件夹 %TEMP%\\VisualStudioTestExplorerExtensions

Read this thread.阅读此线程。

Why is the Visual Studio 2015/2017 Test Runner not discovering my xUnit v2 tests 为什么 Visual Studio 2015/2017 Test Runner 没有发现我的 xUnit v2 测试

You could right-click on a test method and choose the Run Tests/ Run unit Tests option.您可以右键单击测试方法并选择运行测试/运行单元测试选项。 That should bring up the test windows.这应该会打开测试窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM