MSTest: tests do not run because tests are not loaded or selected tests are disabled

I have a C # solution with the following structure:

mySolution myProject myProject.MSTests References Microsoft.VisualStudio.QualityTools.UnitTestFramework sutMSTests.cs 

sutMSTests.cs:

 [TestClass()] public class sutMSTests { [TestMethod] public void MyTest0() { Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(4, 2 + 2); } } 

When I try to run tests through Test, Run, All Tests In Solution, I get the following in the VS2008 status bar:

No tests are performed because the tests are not loaded or the selected tests do not work.

Test, Windows, Test View does not show any tests.

Note. I created the tests manually (works for xUnit.net) instead of using Microsoft wizards.

I compared my manually created MSTest setup with the setup of another test that I generated using the wizard, and they look pretty similar.

Question: What are the most likely causes of the error message above?

Change 2010-02-25: Additional information:
I right-click the Solution Elements folder and select "Add", "Create Project", "Type of Test Projects", "Test Documents :: Visual Studio Project Template".

The new project does nothing by default, the test "TestMethod1" was detected and transferred.
However, my test did not appear ... so I copied and pasted my test method into the default test test project "TestProject1".

My test was detected in "TestProject", but not in its original location.

I carefully compared the files, organization and settings of "TestProject1" with my manually created test project.

At this point, I assume that some settings are created using the Visual Studio Test Project project template, which is not easy to detect.

imo, it’s as easy to create a test project manually as you can create it using the Visual Studio test project template.

Please note: I am not saying that I am against using the Visual Studio Test project template; for me, I like to understand what's behind the curtain, as that makes me imho a much better programmer.

+59
c # unit-testing mstest vs-unit-testing-framework
Feb 22 '10 at 10:50
source share
19 answers

Another for googlers - this problem turned out to be my problem, and it confused me. Make sure your test project is configured to create any configuration for the solution you are using. If the test assembly is not built, VS will not be able to find any tests in the nonexistent assembly, and for a moment you hit your head against the wall :-)

+71
Jun 17 '10 at 1:55
source share

Perhaps a little late, but this question is going well, I thought that I would throw crumbs for future googlers.

Brian Cook suggests checking out ProjectTypeGuids in his blog post about Manually creating an MS test project . Apparently you need the magic GUIDs {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} for C # and {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F} for VB. See His blog post for more details.

If a blog post ever goes away, you need to add the following element to the main property group in the csproj file:

 <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> 
+44
Jun 17 2018-10-06T00:
source share

Another idea for googlers. My problem was to run ignored tests again. The same MS error message appears if you delete the Ignore label. Does not activate automatic restart of the test. In this article, you will go through the last step. http://richallen.blogspot.com/2008/05/ms-test-re-enabling-ignored-tests.html

+10
Mar 11 2018-11-11T00:
source share

The fix is ​​simple, although it should not be necessary if Visual Studio works as it should.

To summarize what others have contributed, especially in this article , this is what ultimately worked for me:

  • Use Configuration Manager to make sure your test project is selected to build any configuration and platform that you use (for example: configuration = Debug and platform = x86).
  • Make sure your method belongs to [TestClass] and that it is marked as [TestMethod] , and DO NOT use the [Ignore] attribute
  • Use the test view to find your test. Test view
  • Open the Properties window ( F4 ) and make sure your test is turned on Enabled
+7
Jul 16 2018-12-12T00:
source share

The original poster did this, but I came here after I did not:

Make sure [TestClass] declared at the top, open in scope:

 namespace XYZ.API.Repository.Tests { [TestClass()] public class ClientTests { 
+4
May 20 '14 at
source share

I just did it manually:

Created a new C # class library project with the following code:

 namespace SO_Answer { public class Class1 { public void Test() { var k = "Hello"; } } } 

Saved the project, and then went to "File-> Add-> New Project" and selected "Test Project". After VS created the unit test project, I added a link to the class library project that I created earlier.

In my test, I have this code:

 namespace Unit_Test { /// <summary> /// Summary description for UnitTest1 /// </summary> [TestClass] public class UnitTest1 { /// <summary> ///Gets or sets the test context which provides ///information about and functionality for the current test run. ///</summary> public TestContext TestContext { get; set; } #region Additional test attributes // You can use the following additional attributes as you write your tests: // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } #endregion /// <summary> /// The test method 1. /// </summary> [TestMethod] public void TestMethod1() { var f = new Class1(); } } } 

The only code I added is the using statement and var f = new Class1(); . Looking at the MSTest runner, I see TestMethod1 .

I can’t think of why your unit tests are not going to. The only thing I had was that I used the MSTest runner to try to test NUnit tests by mistake. Try to start from scratch.

+2
Feb 22 '10 at 23:13
source share

I received the same message, and it turned out that I had a unit test project on a network drive. As soon as I moved it locally, everything worked out fine. Just try if you get this error. John

+2
May 03 '11 at 19:38
source share

This may be another reason. Check if the solution works on the 64-bit version. If so, change it to x86.

+2
Nov 16 '11 at 17:20
source share

This should be a mistake and an absolute pain, especially if you need to reuse each individual testing method. However, a little lateral thinking created the best solution - rename the test class and rebuild. Then rename it back. Seems to work. Oyp - no. Renaming a class works, but when it is renamed, it goes back to the original settings. The trick is to close Visual Studio and delete the test.wsmdi metadata file (visual studio test meta data). It will be regenerated.

+1
Apr 28 '11 at 8:02
source share

When you encounter this problem, in Visual Studio you need to create a test project. 1. Select "Test on the toolbar" and select "New Test". Create your project and at this moment create your test method. It should work after this moment.

+1
Sep 15 '11 at 16:28
source share

For posterity: I only found that tests for marking as static made them silently enter the test list. Apparently this is prohibited.

+1
Nov 18 '13 at 21:49
source share

None of the other answers worked for me. I continued to receive the following message in the output window:

 ------ Discover test started ------ ========== Discover test finished: 2 found (0:00:00.1310428) ========== No tests found to run. 

In my case, the problem only occurred after I created a new configuration called 0-Local. I had to add <DebugSymbols>true</DebugSymbols to the corresponding section of my csproj file, so it looks like this:

 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == '0-Local|AnyCPU'"> <DebugSymbols>true</DebugSymbols> <OutputPath>bin\0-Local\</OutputPath> </PropertyGroup> 
+1
Jul 30 '15 at 18:10
source share

Do you have a VSMDI file in your solution? I believe this file is required (NOT CHECKED).

0
Feb 22 '10 at 23:10
source share

This is a typical problem that I have encountered. but the simplest solution that I followed as my own ... just build the project once and rebuild it again. so that you can solve it.

0
Jan 20 2018-11-11T00:
source share

If this same problem, apart from reading the previous answers, everything looked good.

In my case, I just ran a test suite, made a small change, built a solution, and tried to run a test. No. I tried to build a couple more times and look for problems that other people have tried. Still no.

I hit one of my test methods to add a new one and hit F6 to build a solution, and hit Run Unit Tests.

Bingo! Everything went smoothly.

0
Jul 05 '13 at
source share

Same problem, different reason ...

TestContext MUST be a public variable.

0
Nov 26 '14 at
source share

I used the public TestContext TestContext to write to the test output and changed the scope to private . This made each test incomprehensible. Changed it to public .

0
07 Oct '16 at 9:56
source share

Another for googlers using NUnit, especially those who migrated from MS Unit test to NUnit. Remove the project type. Guides that identify the project as an MS Test project from the project file.

 <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> 
0
Dec 19 '16 at 21:51
source share

If your CLI code (C ++ managed) and your test class inherit from an abstract base class, make sure your test class implements a basic pure virtual method. if you haven’t implemented it, you can see the message "no tests found to run".

0
Mar 21 '17 at 9:35
source share



All Articles