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条回答
Bombasti
2楼-- · 2019-02-01 16:03

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>
查看更多
The star\"
3楼-- · 2019-02-01 16:04

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.

查看更多
放荡不羁爱自由
4楼-- · 2019-02-01 16:06

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
查看更多
不美不萌又怎样
5楼-- · 2019-02-01 16:06

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

查看更多
男人必须洒脱
6楼-- · 2019-02-01 16:07

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

查看更多
劳资没心,怎么记你
7楼-- · 2019-02-01 16:08

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>
查看更多
登录 后发表回答