13

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.

Blake Blackwell
  • 7,575
  • 10
  • 50
  • 67

7 Answers7

27

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.

Sigurbjörn
  • 421
  • 6
  • 9
7

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.

mafu
  • 31,798
  • 42
  • 154
  • 247
  • Where (what) is my test list file? Reopening the solution worked although a pain to do that each time a test is added. – Blake Blackwell Apr 16 '10 at 16:18
  • In your Solution Explorer, there is a folder called "Solution Items". In this folder, there should be at least 2 files. One ending in `.testrunconfig`, the other in `.vsmdi`. Vsmdi files contain test lists. Open the vsmdi file (just double click it). VS will display the Test List Editor. At the upper left, hit the refresh button. – mafu Apr 16 '10 at 16:22
  • Hmmm, refreshing the vsmdi file doesn't work. Any ideas why? – Blake Blackwell Apr 16 '10 at 16:25
  • I'm sorry, I don't know. I usually just full rebuild and/or reopen if a test fails to show up. – mafu Apr 16 '10 at 16:27
  • Ok - thanks for your help. At least the reopen refreshes the list. Perhaps a weird bug in RC1. – Blake Blackwell Apr 16 '10 at 16:29
2

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

MoCapitan
  • 439
  • 4
  • 9
0

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.

0

I had this problem and the solution was embarrassingly simple: Mark the class as public. The test class I created did not have the public access modifier.

A look at the test output window told me everything I needed to know.

Test Output Window

0

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].

jonathan
  • 2,513
  • 2
  • 17
  • 13
0

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

Athadu
  • 71
  • 1
  • 1