MbUnit RowTest
"You said no RowTest post!"
I know I did but this v3 feature I'd like to talk about, Row value headers, let's look at this example.
1: [Test]
2: [Row(1, 3, "test")]
3: [Row(2, 2, "test")]
4: public void Example(int sum1, int sum2, string value)
5: { 6: Assert.AreEqual(4, sum1 + sum2);
7: }
Here we have a row test with sample values (note you can mix types in this way) which seeds the test, so far so not unusual, let's try this however.
1: [Test]
2: [Row(1, 3, "test")]
3: [Row(2, 2, "test")]
4: public void Example(string value, int sum1, int sum2)
5: { 6: Assert.AreEqual(4, sum1 + sum2);
7: }
This test would fail as the Row seeds the test parameters in the order they are set in the Row, so now the string values are seeded with int values. While we could just set the parameters in the right order we can also do the following.
1: [Test]
2: [Header("sum1", "sum2", "value")] 3: [Row(1, 3, "test")]
4: [Row(2, 2, "test")]
5: public void Example(string value, int sum1, int sum2)
6: { 7: Assert.AreEqual(4, sum1 + sum2);
8: }
Same test parameter order as before but the test passes. The reason is the Header attribute, this states to MbUnit how each row test value relates to the test parameters so rather than change our test method we can instead fine tune the test data instead.