One of my favorite tools is Resharper(R#). I can’t say enough about it. Since I started using it, It has significantly increased my productivity. It has come to a point where I refuse to be involved in a .Net project that doesn’t use R#.

One of the great feature of R# is how easy it can integrate with most unit test frameworks. In fact, it natively supports NUnit, and why not, NUnit is the mother of all .Net unit test frameworks.

If you need R# to integrate with the framework you’re using, you have to develop a plugin for it. Luckily, all major frameworks already have such a plugin.

However, when I’ve rarely encountered problems using R# and NUnit, I have been frustrated many times when using MbUnit and xUnit. I can concede that each of these frameworks have advantages over NUnit. However, since NUnit is natively supported by R#, I always tend to choose NUnit for my unit tests.

Here’s a simple example that illustrates my point:

I am currently working on a project that uses xUnit. I went ahead and installed the xUnit contrib and everything looked great and worked great…at first.

Now, suppose you have a class called Processor1. I usually like to create a class called Processor1Test that will serve as a container for all the Processor1 tests. i.e.

using Xunit;

namespace Dummy
{
    public class Processor1Test
    {
        public class When_processor_is_asked_for_something
        {
            [Fact]
            public void Should_not_behave_like_outlook_and_crash()
            {
                Assert.True(1 != 1, "Processor 1");
            }

            [...]
        }

        public class When_blah_blah
        {
           [...]
        }
    }
}

This structure is not unusual and I’m not making any breakthroughs here. If you run this unit test through R#, it runs and fails as expected and xUnit outputs “Processor 1″.

Now let’s add another test for another processor, Processor2.

using Xunit;

namespace Dummy
{
    public class Processor2Test
    {
        public class When_processor_is_asked_for_something
        {
            [Fact]
            public void Should_not_behave_like_biztalk_and_crash()
            {
                Assert.True(1 != 1, "Processor 2");
            }

            [...]
        }

        public class When_another_blah
        {
           [...]
        }
    }
}

Nothing fancy here. Just another set of unit tests for another processor. However, if you run this unit test through R#, none of the tests in this class run…

It’s pretty easy to see why. Even though the class When_processor_is_asked_something is encapsulated in 2 different classes (Processor1Test and Processor2Test) and should be treated as 2 different classes with the same name, R# sees it as one, completely ignoring the container classes. So, when you run the unit tests for Processor 2, the unit tests for Processor 1 are the ones actually being executed.

I hate this since I have now to change my unit test structure and naming to accommodate xUnit by removing Processor1Test and Processor2Test classes. I could then either rename all the When_… classes or just put them in their own namespace. This is what I ended up doing

using Xunit;

namespace Dummy.Processor1Test
{
        public class When_processor_is_asked_for_something
        {
            [Fact]
            public void Should_not_behave_like_outlook_and_crash()
            {
                Assert.True(1 != 1, "Processor 1");
            }

            [...]
        }

        public class When_blah_blah
        {
           [...]
        }
}

No clashes there.