Eddie Garmon's Weblog

some architecture, some c#

NUnit 2.2 Timed Tests...

Well I finally got around to working on some more NUnit enhancements. I have finished creating an extension for a timed test with resolution in milliseconds. I had to make several modification to NUnit.Core.TemplateTestCase to ensure code reuse.

A sample of a the new extension is shown below:

using NUnit.Extensions;
namespace NUnit.Extensions.Tests {
  [TestFixture]
  public class TimedTestFixture {
    public TimedTestFixture() {}

    [TimedTest(5000)]
    public void NapOk() {
      Thread.Sleep(2500);
    }

    [ExpectedException(typeof(TestTimeoutException))]
    [TimedTest(200)]
    public void NapTooLong1() {
      Thread.Sleep(500);
    }

    [TimedTest(2000)]
    [ExpectedException(typeof(TestTimeoutException))]
    public void NapTooLong2() {
      Thread.Sleep(500000);
    }
  }
}

If the TimedTest attrribute is defined with a negative timeout, the test is run as if it were declared as a standard Test attribute.

Get the source packaged along with my ObjectGraphAssert extension here.

Comments

bigjuju said:

can you give me an example of the usefulness of a timed test? i can only think of production environment tests.
# February 12, 2005 2:27 PM

Paul Milburn said:

Eddie...

this sounds like a fab extension. However the link to the zip isn't working... any chance you could update the link?

# July 4, 2007 6:13 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)