Charlie and the NUnit team have been working hard on NUnit 2.5 and over the last weekend the NUnit 2.5 RTM was released, a huge kudos to Charlie and the team on getting this out. NUnit 2.5 has loads of new goodies, parameterized tests (like MbUnit) and Theories (like JUnit and XUnit.net) caught my eye, seeing parameterized tests in NUnit really shows how much MbUnit has brought this concept into the .NET mainstream and it is exciting to see in NUnit. So lets take a look.
1: using NUnit.Framework;
4: public class SummerTest
6: [Test, Sequential]
7: public void TestAddSequential([Values(2,4)] int expected,
8: [Values(1,2)] int value1,
9: [Values(1,2)] int value2)
11: Assert.AreEqual(expected, value1 + value2);
14: [TestCase(2, 1, 1)]
15: [TestCase(3, 1, 2)]
16: public void TestAddCombin(int expected, int value1, int value2)
18: Assert.AreEqual(expected, value1 + value2);
In both cases we are seeking to add two numbers together and compare to a result. I have shown two slightly different ways of approaching the same test, the first test sets values on the sums and expected within the parameter, the second test shows how you can also split them out.
The only thing I recommend is using the TD.NET beta with NUnit 2.5 or your tests won't work correctly.