I’ve been playing around with MBUnit for only a few hours, but I’m way impressed with it so far. Its table-based testing via the [RowTest()] attribute is killer. I love that I can combine rows of input and catch Exceptions all in one test:
[RowTest()]
[Row(33.22, 80, 3322)] //border top
[Row(33.22, 20, 664.40)] // middle
[Row(33.22, 1, 33.22)] // border bottom
[Row(33.22, 0, 0)] // border bottom (zero)
[Row(50, 81, 0, ExpectedException = typeof (ArgumentException))] //border over max
[Row(50, -1, 0, ExpectedException = typeof (ArgumentException))] // border under min
public void CheckWagesHourly(double rate, double hours, double wagesExpected)
{
IEmployee pers = TestFactory.CreateDefaultPerson();
pers.WageType = Employee.WageTypes.HOURLY;
pers.HourlyRate = rate;
Payroll pay = new Payroll();
double wages = pay.ComputeWages(pers, hours);
Assert.AreEqual(wagesExpected, wages, 0, "Wages/hourly/normal + border + OT");
}
I get a normal value and five border tests (top, bottom, over, under, zero) all in one fell swoop. This same test would have taken me six separate tests in NUnit. You can also put in a delta parameter for a row, enabling the test to pass if it’s within plus/minus of the delta factor. Wow.
Note that I’ve got a TestFactory class creating objects for my tests? MBUnit has a [Factory] attribute which lets you mark a method as providing basic input for other test methods, all in a much cleaner fashion. I’m off to explore that next.
MBUnit looks way cool. There are several cons about it (transition of project personnel, sporadic availability of the project’s Wiki, a few odd behaviors), but Andrew Stopford has taken over the project and is very responsive. He bailed me out of a couple hitches and provided an update, all in the space of a couple hours today.
Better yet, support for it is wrapped right into TestDriven.NET which you ought to run and install Right This Very Instant if you’re not using it already. There’s also a very nice HTML report which will pop up right inside VS if you’re using TestDriven to execute your tests.
I think this will be a great part of my open source test tools presentation next week.
One self-inflicted wound I gave myself today: I ran into a MbUnit.Core.Exceptions.NotEqualAssertionException and a “FailedLoading(Parameters count are not equal Equal assertion failed” message in the report. It took me a bit of time to figure out I’d left in a [Test] attribute from an NUnit test I copied over and changed to a [RowTest()]:
[Test]
[RowTest()]
[Row(33.22, 80, 3322)] //border top
…
public void CheckWagesHourly(double rate, double hours, double wagesExpected)
{
Oops. Hey, I make the mistakes so you don’t have to.
1 comment:
Welcome to the wonderful world of MbUnit! ;) One lament I have is how ignored it is despite how much better (in my opinion) it is compared to NUnit.
You should also check out the TypeFixture...
http://haacked.com/archive/2005/10/18/SwitchingToMbUnit.aspx
Post a Comment