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:19
  • I know that the unit tests are not found if the solution is not built, so that is something to try (Build the solution), but that solution is like the help desk asking if your computer is plugged in...
  • After a clean rebuild did not fix the problem for me, running a full batch build did fix it.
查看更多
干净又极端
3楼-- · 2019-01-06 10:20

If you load a Visual Studio (VS 2015 Community in my case) solution from a network share or My Documents directory that is part of a share, you will get into this trouble. I solved it by moving the solution and its underlying projects to a local folder.

查看更多
【Aperson】
4楼-- · 2019-01-06 10:21

I had the exact same problem.

It was due to incompatible version of NUnit I'd added to my project (3.2.0) and the Test Adapter I had installed (2.0.0).

To fix, use "Tools > Extensions and Updates" and search for NUnit3 Test Adapter, it discovered my tests after that.

Cheers

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

For future googlers I had a rare scenario that caused this.

On my base test class I had a property named TestContext. This interfered with MSTest's reserved TestContext property causing all my tests to be hidden from VS/Resharper except one (which did not inherit from the base).

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-06 10:24

for me it was changing 'solution configurations' to Debug (instead of Release).

查看更多
一纸荒年 Trace。
7楼-- · 2019-01-06 10:24

Try building all projects as MSIL (Any CPU) instead of x86/x64. Worked for me strangely

查看更多
登录 后发表回答