Recently I was asked how to separate multiple test asserts based on different data from the test itself to reduce code duplication and/or have better reporting of the multiple assertions in the test instead of just a single pass/fail, even if the test actually 10 different tests.
MbUnit contains a really nice feature called RowTest which allows you to have a single test, but with multiple different sets of data to execute a test against. Each set of data is then executed separately as a unique test.
An example of the test method is this:
[Row(1, 2, 3)]
[Row(0, 0, 1)]
[Row(-1, -2, -3)]
[Row(2, 2, 5, ExpectedException = typeof(MbUnit.Core.Exceptions.AssertionException))]
public void TestForAddMethod(int a, int b, int expected)
int test = MyMethods.Add(a, b);
This then creates four separate tests, with one expecting to fail.
When one test fails, it doesn’t stop all the other tests executing. This is a great feature to improve your unit testing code.
Download the full code class, which includes the NUnit and MbUnit style, from:
Just one of the many great features within the MbUnit framework.