MSTest Not Finding New Tests

2019-01-25 06:46发布

问题:

Using VS2010, I can't seem to add additional test methods. If I set up my project like this

[TestMethod]
public void Test1()
{
   Assert.AreNotEqual(0,1);
}

[TestMethod]
public void Test2()
{
   Assert.AreNotEqual(0,1);
}

The only test that shows up in my Test View is Test1. How do I make sure Test2 gets in to that list?

EDIT: Additional tests that weren't initially created are not added to the list of tests. So if I was to add Test3 after running tests, then Test3 would not get added.

回答1:

Simplest way: Reopen the solution.

You can also open your test list file (the "vsmdi" file in your Solution Items folder) and hit the "refresh" button there.

A full rebuild of your solution works sometimes, too.



回答2:

I ran into the same problem with not discovering new test methods after I had uninstalled ReSharper and updated to Visual Studio 2010 SP1.

I fixed the issue by going to Tools > Options > Test Tools > Test Project and unchecked "Disable background discovery of test methods".

It worked re-opening the solution but not doing a full clean and rebuild.



回答3:

For me nothing of the above worked. I compared my csproj file with one that worked and added the project type guids from the other test project to the one that didn't work.

So try to add the type Guids to your project file where the [TestClass] and [TestMethod] is included with a text editor:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
...
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    </PropertyGroup>
...
</Project>

After adding this and a refresh in the test list editor I instantly saw my tests and CTRL-R-T worked.

Regards, Michael



回答4:

Make sure your tests have prefixes such as [TestClass] for the class and [TestMethod] for the methods. I had a case where I did not realize that I was trying to run tests written in another framework. In my case it was [TestFixture] and [Test].



回答5:

Deleting the file with the extension '.sln.docstates' that is in the project folder fixed the issue for me.

Not sure if it matters - but I also deleted all the files in the TestResults folder.

Athadu



回答6:

For me, delete of .suo and .sdf files related to the solution helped. Right after reopening the solution, the tests were in the List Editor.