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条回答
小情绪 Triste *
2楼-- · 2019-01-06 10:02

go to the project menu > Configuration Manager check your test project platform matches the rest of the project and is check to build then rebuild.

查看更多
地球回转人心会变
3楼-- · 2019-01-06 10:02

I came across the same issue. And investigated and found that the dll's were not build, and put in the right folder. as soon as I changed my configuration they appeared. - the Projects build options, what folder should be used? - the build menu entry build configuration, they should be checked.

that fixed it for me.

查看更多
祖国的老花朵
4楼-- · 2019-01-06 10:03

Some things I've noticed I have to do from time to time to get tests to show up properly.

  1. If your solution is in a protected drive that you need administrator access to read/write, sometimes only a portion of the tests come up. Definitely run VS as administrator in that case.

  2. If your solution is 64 bit, make sure that Test > Test Settings > Default Processor Architecture is set to x64. Sometimes it gets set to x86. Set it to x64, then rebuild.

  3. Sometimes just restarting Visual Studio does the trick because the test explorer will start up again.

  4. Don't forget to actually build the test project/solution. (If you want it to get built with the rest of the projects, right-click on your solution > Properties > Configuration Properties > Configuration > check the "Build" box for your test project)

  5. Ensure the tests are in a public section of your test class

查看更多
▲ chillily
5楼-- · 2019-01-06 10:03

I was facing the same problem and I've remembered, again (this situation happened before), that selecting "Mixed Platform" on the solutions platform menu works, as well as the other answers.

查看更多
萌系小妹纸
6楼-- · 2019-01-06 10:03

Had the same issue; tests suddenly stopped being discovered.

Nunit Test Adapter had become disabled somehow. Clicking enable in the extension manager fixed it for me.

查看更多
forever°为你锁心
7楼-- · 2019-01-06 10:05

Make sure your test class is public so it can be found. And if you're referencing another class, make sure of the same.

Also, sometimes if you have no Asserts or you're not decorating the test with a [TestMethod], a test might not be recognized.

2 more things: 1) Async unit tests act funny at best, and none at all at worst. Have a look at this article by Stephen Cleary and keep from there if it interests you.

2) If you use NUnit and you run into the same issues, keep in mind it's [TestCase] for Nunit, instead of [TestMethod]

Having said the above, here's an article I've posted on the code project, with both MSTest & NUnit, in case you want to give it a spin and make sure you're not missing anything.

查看更多
登录 后发表回答