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:07

You just need to install this package only:

NUnit TestAdapter NUnit TestAdapter

查看更多
Juvenile、少年°
3楼-- · 2019-01-06 10:09

While AndyG's solution works, a more lasting solution could be to set the PreferredToolArchitecture environment variable to "x64", either by:

How to make Visual Studio use the native amd64 toolchain

or by:

  • Control Panel | System and Security | System | Advanced System Settings|Environment Variables
  • PreferredToolArchitecture = x64
  • DefaultToolArchitecture = Native64Bit
  • PROCESSOR_ARCHITECTURE = x64
  • ProcessorArchitecture = x64
查看更多
劳资没心,怎么记你
4楼-- · 2019-01-06 10:09

After spending 2 days... none of the above worked for me. The only "solution" was: Go to project properties -> Build Tab. Then click Advanced button on the right bottom corner of the pane. Change "Debug Info:" to "full" and click OK.

Here are the screen shots: enter image description here

enter image description hereenter image description here

查看更多
劫难
5楼-- · 2019-01-06 10:10

I'm having this issue from time to time. What works for me is to shutdown Visual Studio and go to folder:

%LocalAppData%\Microsoft\VisualStudio\12.0\ComponentModelCache

and delete it content.

Once you open Visual Studio and load your project again Test Explorer should contain back your tests

查看更多
混吃等死
6楼-- · 2019-01-06 10:10

My problem was because my unit test method wasn't void, and it was receiving parameters.

查看更多
再贱就再见
7楼-- · 2019-01-06 10:11

I have found that unit test methods marked as async void aren't discovered by the VS Test Explorer. This seems to be because VS would not have any way to wait for a test to finish and decide if it succeeded or not. If you absolutely need to have a test method to run asynchronously then get it to return a Task instead like async Task. I found that this fixed the issue for me.

查看更多
登录 后发表回答