Search code examples
unit-testingnunitmbunit

MbUnit vs. NUnit


I read that MbUnit is NUnit on steroids, but I don't see why. From what I have read on here, I hear that NUnit is more popular over MbUnit. One of the main reasons is because it has a fluent interface. Is this the only reason?

Why should I prefer MbUnit over NUnit, or vice-versa?


Solution

  • NUnit started as a port of JUnit, and has been around a long time. MbUnit came after the fact, and it brought "generative" unit testing. This means it has the ability to take a single unit test and generate several from it. One way to do this is the [RowTest] attribute.

    Where a typical unit test will not take any parameters, a RowTest will take parameters and generate multiple tests from that. I believe that NUnit has the concept of RowTest now as well.

    [Test]
    [Row(1, 1, 2)]
    [Row(2, 2, 4)]
    [Row(1, 2, 3)]
    public void X_plus_Y_equals_Z(x, y, z)
    {
      Assert.AreEqual(z, x+y);
    }
    

    This will result in three tests being run in the test runner. There are also features for rolling back database transactions.

    NUnit has the fluent interface for assertions, which is nice, but not really a selling point. NUnit probably also has some better tool support (ReSharper's test runner works with NUnit out of the box, but requires plugins for MbUnit).

    In the end, you should pick one framework and go with it. The skills you pick up are very portable from one framework to another.