MSTest: No tests are run because no tests are load

2019-02-01 15:42发布

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.

18条回答
女痞
2楼-- · 2019-02-01 16:12

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-02-01 16:15

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

查看更多
萌系小妹纸
4楼-- · 2019-02-01 16:16

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
    {
查看更多
做个烂人
5楼-- · 2019-02-01 16:16

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.

查看更多
Bombasti
6楼-- · 2019-02-01 16:17

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>
查看更多
三岁会撩人
7楼-- · 2019-02-01 16:18

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.

查看更多
登录 后发表回答