Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper running all tests when only a single one is selected

I'm using Resharper 4.5 with Visual Studio 2008 and MBUnit testing, and there seems to be something odd with using ReSharpher to run the tests.

On the side there are the icons beside the class each test method with the options Run and Debug. When I select Run it just shows me the results of the single test. However I noticed that the test was taking a considerably long time to run.

When I ran Sql Server profiler and start stepping through the code, I realized that its not just running the selected test, but every single one in the class. Is there any reason it makes it look like its only running one unit test while actually running them all?

Its getting to be a pain waiting for all integration tests to run when I only care about the reuslt of one, is there any way to change this?

like image 437
Brandon Avatar asked Jul 10 '09 16:07

Brandon


3 Answers

I just encountered this today and I think I might have realized what causes this bug, I had my methods named similarly

    [TestMethod]
    public void TestSomething()

    [TestMethod]
    public void TestSomethingPart2()

I saw that running TestSomething() would run both, however running TestSomethingPart2() would not. I concluded if you name methods that an exact match can occur for the method name it will run the test. After renaming my second test to TestPart2Something this issue went away.

like image 121
Chris Marisic Avatar answered Sep 20 '22 08:09

Chris Marisic


I can confirm that this is a problem with ReSharper 5.1.

To reproduce run test A from my sample code below (all tests will execute); run test AB (all except A will execute); etc:

[TestMethod]
public void A()
{
    Console.WriteLine("A");
}

[TestMethod]
public void AB()
{
    Console.WriteLine("AB");
}

[TestMethod]
public void ABC()
{
    Console.WriteLine("ABC");
}

[TestMethod]
public void ABCD()
{
    Console.WriteLine("ABCD");
}

[TestMethod]
public void ABCDE()
{
    Console.WriteLine("ABCDE");
}

It took me ages to work this out. I had the remote debugger attached to a development server, and it was breaking a bit more often than I was expecting it to...

It seems to be doing a StartsWith instead of a Contains as others have said. The workaround is to not have test method names that start with the name of another test method name.

like image 22
sheikhjabootie Avatar answered Sep 21 '22 08:09

sheikhjabootie


I hope this shows up under Chris post.

I had a similar situation that confirms the behavior he noticed.

[TestMethod()]
public void ArchiveAccountTest()

[TestMethod()]
public void ArchiveAccountTestRestore()

So running the first method would execute both and running the second would not. Renamed my second method to TestRestore and the problem went away.

Note: I'm using Resharper 5.1 so it's still a problem.

like image 41
DaVinciCoder Avatar answered Sep 20 '22 08:09

DaVinciCoder