Extending MbUnit

I’ve been using MbUnit for a little while now and it pretty much rocks. The only problem I had was with the Duration attribute. It allows you to make sure that a test runs within a certain amount of time. It works fine but unfortunately each of my computers perform the tests in a different amount of time. There are also occasional glitches when the computers don’t run them quite as fast as they should.

Luckily MbUnit is extensible so I’ve been able to create my own version of the Duration attribute.

Usage is like this,

[Test]
[MultiMachineDuration(new string[] { "COLIN-PC", "PHOTEK" }, new double[] { 0.28, 0.41 })]
public void SimplePerformanceTest()
{
Mylib.DoSomethingIntense();
}

Note that the syntax is fairly crude at the moment. The arrays must be matched, a list of machines and a list of times that the method shouldn’t run for longer than. If the test is run on a machine not mentioned in the array it will fail because there is no time setup. It will mention the machine name it’s looking for in the exception.

If you want to download it you can get the class from http://colinnewell.co.uk/Downloads/PerformanceAttribute.zip. You just need to include it your project or create a library for it to use it.

Advertisements