Visual Studio 2013 doesn't discover unit tests

2019-01-06 10:01发布

I have a simple solution in visual studio 2013 that is composed by one web project, one library project and one unit test project. When I open the solution and try to run the unit tests they are not discover by visual studio. To run the tests I try to go to the menu and choose Test -> Run -> Run all tests or by opening the test explorer window. By those to methods visual studio doesn’t discover any tests in the solution.

Creating first a simple unit tests project and try to run the test, visual studio know discover the test and I can run it. Then, if I open my previous solution visual studio now discovers all the tests. I try to save my solution but closing it and reopening, without creating a unit test project first, the visual studio doesn’t find the tests again. This is a very strange behave that I don’t know why this is happening.

I used to working alone in this project that was using the source control git integrated with the visual studio team foundation. The problem of visual studio not discover the unit tests start when a new element came to the project and when I need to recreate the solution through the source control online. Before this, all tests always been discovered by visual studio.

For creation the unit tests I use the dll Microsoft.VisualStudio.QualityTools.UnitTestFramework. My version of visual studio is: Microsoft Visual Studio Express 2013 for Web Version 12.0.30723.00 Update 3. My version of .net framework is 4.5.50938.

All of my tests are like this:

[TestClass] 
public class Service1Test 
{ 
    [TestMethod] 
    public void Test1() 
    {
        Assert.IsTrue(True); 
    } 
}

30条回答
孤傲高冷的网名
2楼-- · 2019-01-06 10:12

I'd managed to add mine as

public static void TestMethod1(){}

started working once I removed static....

查看更多
戒情不戒烟
3楼-- · 2019-01-06 10:12

I had the same problem until I realized I made a cut/paste error and left off [Test Method] before the test.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-06 10:15

Just ran into this as well as I didn't see a similar case that was similar to mine.

In the .csproj file of my test project, NUnit reference privacy was set to False:

<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
  <HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
  <Private>False</Private>
</Reference>

After I set <Private> to True it worked.

查看更多
三岁会撩人
5楼-- · 2019-01-06 10:15

Sorry for adding to the long list, but I had a completely a different problem. First, I would like to mention I discovered my issue when clicking 'Run All' in the Test Explorer and then watching the build output window in Visual Studio. You have to actively watch it, as afterwards the message disappears.

As for the issue, it looks like during the scanning of the tests, the DLL gets loaded and its test types are enumerated. This causes the references to be loaded and if any failure occurs during this process, the tests will not be shown in the explorer. I had two issues preventing the test DLL to be successfully loaded:

  • There was still a binding redirect left in the config file (redirecting to a version lower version NHiberate than what was referenced in the test project).
  • A conflicting assembly reference (2nd level references not being able to load). AsmSpy is btw a great tool to hunt for these.
查看更多
Luminary・发光体
6楼-- · 2019-01-06 10:16

I had the same issue but none of the other solutions worked. Turns out that I was using the NUnit 3 framework with the 2 adapter.

If you're using NUnit 3, go to Extensions and Updates and install the NUnit3 Test Adapter.

查看更多
虎瘦雄心在
7楼-- · 2019-01-06 10:16

XUnit users may notice Test Explorer window no longer lists any tests. To make tests discoverable again try this important tip, highlighted below.

If you're having problems discovering or running tests, you may be a victim of a corrupted runner cache inside Visual Studio. To clear this cache, shut down all instances of Visual Studio, then delete the folder %TEMP%\VisualStudioTestExplorerExtensions. Also make sure your project is only linked against a single version of the Visual Studio runner NuGet package (xunit.runner.visualstudio).

Type in TEMP to find target folder

查看更多
登录 后发表回答