MSTest: No tests are run because no tests are loaded or the selected tests are disabled
Asked Answered
D

18

65

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 the tests via Test, Run, All Tests In Solution, I get the following on the VS2008 status line:

No tests are run because no tests are loaded or the selected tests are disabled.

Test, Windows, Test View shows no tests.

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

I've compared my hand created MSTest setup to the setup another test that I generated using the wizard and they appear to be sufficiently similar.

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

Edit 2010-02-25: More information:
I right clicked the Solution Items folder, and choose Add, New Project, type Test Projects,Test Documents::Visual Studio Test Project template.

The new project's default do nothing test "TestMethod1" was detected and passed.
However, my test did not show up ... 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 closely compared the files, organization, and settings of "TestProject1" with my hand created test project.

At this point, I am guessing that some setting gets made by the Visual Studio Test Project template that is not easily detectable.

imo, it should be just as easy to create a test project by hand as it is to create one with the Visual Studio Test Project template.

please note: I'm not saying that I'm against using the Visual Studio Test Project template; for me, I like to understand what's behind the curtain since this makes me imho a much better programmer.

Dorelle answered 22/2, 2010 at 22:50 Comment(1)
I appreciate all of the participation and suggestions in the answers and comments below; given a choice, xUnit.net (Jim Newkirk, Brad Wilson) is my preferred unit testing framework. I think the problem was MSTest may have been MSTest was creating too many files and deleting them may have fixed the problem. I say may have because I can not remember. At the time I was researching .NET unit testing frameworks. That project is currently on my back bench. I'll try to get back to this in the future. Thank you all. I'll be back. g.Dorelle
S
76

Another one for the googlers - this one turned out to be my problem, and it's embarrassingly boneheaded of me. Make sure that your test project is set to build in whatever solution configuration you're using. If the test assembly isn't being built, VS won't be able to find any tests in the non-existent assembly, and you'll bang your head against the wall for a while :-)

Solipsism answered 17/6, 2010 at 1:55 Comment(7)
you're right. You need to ensure the assembly is being built. In my case, this error was due to a combination of the following: (a) in the "Configuration Manager", the "build" button wasn't ticked (b) all other assembles were set to x32, this one was set to "Any CPU" in the "Configuration Manager" (c) it was complaining that it needed an assembly signed so I needed to set this in the project properties.Cohette
Ha ha! Classic - this just got me too.Nightgown
Thanks. Was checking host settings and the vsmdi being confused but this helped me out.Jeopardy
Heh, thanks for this. Got me too - so simple! Why it was set not to build is another matter...Shipworm
cut-paste of newly created test project apparently removes it from build and this issue :(Flexor
Wow, I just wasted an hour of my life troubleshooting this. Doh!Shackle
amazing, this was it!Melanochroi
S
47

Possibly a bit late, but this question googles up well, I thought I'd throw some crumbs in for future googlers.

Bryan Cook suggests checking the ProjectTypeGuids in his blog post about Manually creating a MS Test Project. Apparently the magic GUIDs you need are {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.

In case the blog post ever goes away you need to add the following element in the main property group in the csproj file:

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Solipsism answered 17/6, 2010 at 1:42 Comment(2)
Worked like a charm -- awesome.Sewoll
I had to manually add this line to the csproj file. <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>Urgency
D
10

Another idea for the Googlers out there. My problem was trying to get ignored tests running again. Same MS error message occurs if you remove the Ignore label. Does not automatically re-enable the test. This article takes you through the last step. http://richallen.blogspot.com/2008/05/ms-test-re-enabling-ignored-tests.html

Dodge answered 11/3, 2011 at 22:14 Comment(1)
buff... thanks man, I was about to throw the computer through the window. Hopefully it will be fix in Visual Studio 2083Wittie
P
9

The fix is simple, even though it shouldn't be needed, if Visual Studio worked as it should.

To sum up what others have contributed, particularly in this article, here's what ultimately worked for me:

  • Use the Configuration Manager to make sure your test project is selected to build in whatever configuration and platform you're using (ex: configuration=Debug and platform=x86)
  • Make sure your method belongs to a [TestClass] and that it's both marked [TestMethod], and NOT using the attribute [Ignore]
  • Use Test View to find your test. Test View
  • Open your Properties window (F4), and make sure your test is enabled Enabled
Peart answered 16/7, 2012 at 19:36 Comment(2)
It's not obvious that you can add a new test project to a VS solution, hit F6 to build it, and it isn't built because it's not part of the configuration... then you go to the test list editor and pull your hair out for 30 minutes wondering why no tests appear! Thanks Gustavo.Lanfranc
Totally! I wish the UI would give you some indication that a given project isn't built for a given configuration--kinda the way it looks when you have C++ macros that grey out when they're not active.Peart
A
4

The original poster did do this, but I arrived here after not having done this:

Be sure that [TestClass] is declared at the top, public in scope:

namespace XYZ.API.Repository.Tests
{
    [TestClass()]
    public class ClientTests
    {
Appal answered 20/5, 2014 at 0:1 Comment(0)
P
2

I've just manually done this:

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 chose 'Test Project'. After VS created the unit test project, I added a reference to the class library project 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 was the a using statement and the var f = new Class1(); statement. Looking at the MSTest runner, I can see TestMethod1 appear.

I can't think of a reason why your unit tests are not being picked up. The only time I've had this is because I was using the MSTest runner to try and view NUnit tests by mistake. Try starting from scratch.

Portable answered 22/2, 2010 at 23:13 Comment(1)
You're a genius. The problem was adding the wrong solution type (Class Library instead of Test).Edmondo
O
2

I was receiving the same message and it turned out to be that I had my unit test project on a network drive. Once I moved it local it ran fine. Just something to try if you get this error. John

Oringas answered 3/5, 2011 at 19:38 Comment(0)
U
2

This could be another reason. Check whether the solution is running on 64bit. If so change it to x86.

Unseemly answered 16/11, 2011 at 17:20 Comment(0)
M
1

This must be a bug and is an absolute pain especially as you have to reenable every single test method individually. However a bit iof lateral thinking produced a better solution - rename the test class and rebuild. Then rename it back. Seems to work. Ooops - no it doesn't. Renaming the class works but when it's renamed back it reverts to the original settings. The trick is to close down Visual Studio and delete the .vsmdi (visual studio test meta data) file. This will be regenrated.

Merrow answered 28/4, 2011 at 8:2 Comment(0)
L
1

When you run into this issue, in Visual Studio, you have to create a Test Project. 1. Select Test in Tool bar and choose "New Test". Create your project and at this point create your test method. It should work after this point.

Laughing answered 15/9, 2011 at 16:28 Comment(0)
A
1

For posterity: I just found that marking tests as static made them silently fail to appear in the test list. Apparently that isn't allowed.

Authenticate answered 18/11, 2013 at 21:49 Comment(0)
F
1

None of the other answers worked for me. I kept getting 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 relevant 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>
Flunkey answered 30/7, 2015 at 18:10 Comment(0)
B
0

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

Beatific answered 22/2, 2010 at 23:10 Comment(3)
The .vsmdi file appears to be not required. As described above in my edit, I created a test project with the vs template and saw the default test. After I deleted ALL .vsmdi files, the tests in the project created with the template still run. I'm trying to understand what special "tweak" the template does. It's frustrating because it's so easy with xUnit.net to manually create a test project. Thank you for your suggestion.Dorelle
No worries. I had to use MS Test my past few jobs and found its dependence on the VSMDI file a huge pain. It got even worst with certain source control providers. Good luck.Beatific
For some reason I had 2 VSMDI files in my VS2008 solution. It used to work fine but no more :( So I closed VS, deleted the VSMDI files, reopened the solution and run all tests in solution. This displayed an error but it seemed to recreate a new VSMDI. Running all tests in the solution then started working again. Phew!Feld
L
0

this is typical problem i have faced too. but the easiest solution I followed as my own is...just to build the project once and rebuild it again. so that you can resolve it.

Likely answered 20/1, 2011 at 5:5 Comment(0)
H
0

Had this same issue but reading over the previous answers, everything looked good.

In my case, I had just run the test suite made a small change, built the solution and tried to run the test. No go. I tried building a couple more times and looking for problems other people had tried. Still no go.

I hit enter in one of my test methods to add a new and hit F6 to build the solution and clicked run Unit Tests.

Bingo! Everything ran smoothly.

Herodotus answered 5/7, 2013 at 20:31 Comment(0)
L
0

I was making use of a public TestContext TestContext method to write to the test output and changed the scope to private. This made every test not discoverable. Changing it back to public helped.

Lampas answered 7/10, 2016 at 9:56 Comment(0)
V
0

Another one for googlers using NUnit, especially those who have migrated from MS Unit test to NUnit. Please remove the project type Guids that are identifying the project as MS Test project from the project file.

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Victoria answered 19/12, 2016 at 21:51 Comment(0)
F
0

If your code is CLI (managed c++) and your test class inherits from an abstract base class, make sure that your test class implements the base's pure virtual method. if you didn't implement it, you may see the "no tests found to run" message.

Fleuron answered 21/3, 2017 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.