views:

204

answers:

5

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?

A: 

When you right-click in the editor, the context menu appears from which you can run and debug tests. Right-click inside a test method to run or debug that single test. Right-click outside of any test method to run or debug the entire test class contained in the current file.

Robert Harvey
So the icon beside the method declaration that says "(Method Name) Run" really means "Run entire class"? That seems very misleading...
Brandon
I didn't write it, so I can't really say. Did the right-click context menu work?
Robert Harvey
No, its still running them all, even when I right click and say Run Unit Tests.
Brandon
A: 

The current release of Gallio includes a Unit Test runner with MbUnit (and NUnit) support built-in.

From the Resharper menu, you have the option of running a Single unit test or all Tests in your solution. What is cool, is that the Keyboard-shortcuts for this are:

  • Alt + R, U, R - Run test from current context (if you are at a [Test] level, it runs one test, if you are at a [TestFixture] level, it runs all in the fixture!)
  • Alt + R, U, N - Runs all Unit Tests in your Solution

I highly recommend that you uninstall your current Gallio and then check C:\Program Files\Jetbrains\Resharper\plugins\bin and clear out and files there. Then install Gallio afresh.

Once you've done this, you should startup VS2008 and goto at the Resharper | Plugins menu to check that the Gallio plugin is active. This will give you support for MbUnit.

Brett Veenstra
+2  A: 

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.

Chris Marisic
That is quite interesting. Has anyone else confirmed this issue?
Brian T Hannan
+1  A: 

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.

DaVinciCoder
+1  A: 

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.

Xcaliburp