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

2 thoughts on “Extending MbUnit

  1. Neat trick!
    Long term I’d be worried about the amount of maintenance required.

    Another way to do performance regression testing would be to designate a single authoritative benchmark machine. You can collect historical XML reports from test runs performed on that machine. After running a test, you can issue warnings if certain tests take more than X% longer than the previous average.

  2. That’s true and not a bad idea.

    My motivation for doing it was that I wanted to be able to have performance tests that would prevent me from rolling a release if they failed.

    I want to be able to do that from multiple machines because I don’t have a centralized build server.

    To tell the truth I would like to look into the syntax to see if I could do it with multiple attributes, one for each machine. Kind of like the [Row()] attributes.

    I just haven’t had a chance yet, I figured I’d put this out to see what people thought of it. That and I’m curious about which way the MbUnit v3 development is going because I can’t see a DurationAttribute in it yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s