visual-studio-2008unit-testingnunitmstestintegration-testing

Ms Test or NUnit?


Is there any advantage to picking NUnit for unit/integration testing vs the built in MsTest?


Solution

  • They are pretty similar. Differences are subtle.

    You can write

    [TestCase(1, "one)]
    [TestCase(2, "two)]
    [TestCase(3, "three)]
    [TestCase(4, "four)]
    public void CanTranslate(int number, string expectedTranslation)
    {  
         var translation = _sut.Translate(number);
    
         translation.Should().Be.EqualTo(expectedTranslation);
    }
    

    rather than writing 4 tests or using a cycle inside the test. Failing tests' error messages will be much clearer and test results will be always conveniently grouped.

    For example

    [Test, Combinatorial]
    public void MyTest([Values(1,2,3)] int x, [Values("A","B")] string s)
    {
        ...
    }
    

    which is equivalent to running the tests

    MyTest(1, "A")
    MyTest(1, "B")
    MyTest(2, "A")
    MyTest(2, "B")
    MyTest(3, "A")
    MyTest(3, "B")
    

    (see the original page here)

    for example

    Assert.That(result).Is.GreaterThan(9)
    

    rather than

    Assert.Greater(9, result);
    

    With SharpTestEx you can even write:

    result.Should().Be.GreaterThan(9);
    

    and take advantage of the strong typed IntelliSense.