Eddie Garmon's Weblog

some architecture, some c#

February 2005 - Posts

Why a Timed Test in NUnit 2.2?

In response to questions about the value add of Timed Tests in NUnit:

There are several uses for timed tests, most of which fall under the umbrella of performance testing.

1) You have a piece of code/hardware that you want certain functions to complete in less than a specified amount of time. If you already have a NUnit test that exercises this functionality, all you have to do is change your [Test] attribute to a [TimedTest(time limit)] attribute an now your unit test plays 2 roles, functional unit test, and performance test.

2) Performance optimization regression testing. Say you have a segment of code that has been optimized, and has a timed test that verifies execution in less than a specified amount of time. When you run this unit test as you add to/refactor your code base, you will immediately be notified if you introduce code that has less performance than your tests allow.

3) Quickness in creating new performance tests. This is as simple as adding a new NUnit test fixture, and adding a timed test.

4) Integration of performance tests with unit tests. If you know how to write one, you know how to write the other. You don't need to integrate another testing framework to do basic performance monitoring.

5) Time limit on long running tests. Once a test times out, execution of the test stops, guaranteeing that a long running test will not slow up the build/test/deployment procedure that you have in place.

6) Add a category to all of your timed tests and with-in NUnit, you have a predefined set of performance tests to run, without checking boxes.

Also of note: I made a change to the code so that only the actual test is timed, not the setup and tear down as well. Get the updates here.

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.

Visual Studio .Net C# Item Templates Version 1.1.0

Updates were made for design time support for the 2 typed collection classes, courtesy Brendan Tompkins. I also updated the Registry class, as I found that it was not in sync with the template that I currently use.

Keep the ideas comming.

Get the Version 1.1.0 installer here.

More Visual Studio Templates (with Installer)

Due to feedback from local sources, I am urged to share my most common Visual Studio Templates.  Packaged in a MSI installer for both VS 2002 and VS 2003 are the following templates:

  • a class template
  • an enumeration template
  • an exception template
  • a nunit test template
  • a registry template
  • a typed collection template
  • a typed hashed collection template

Points of note: When creating a typed collection, or a typed hashed collection, name the class as %Type%Collection. For example, a typed collection of 'Orange' should be 'OrangeCollection' and a typed hashed collection of 'Apple' should be 'AppleCollection'. None of the other templates have any naming restrictions.

Get the installer here.

If you have ideas for other templates, please let me know and I will see about including them.

Update: These templates are in C# only at the moment. They are Project ITEM templates, not project templates, and are accessable via the Add>Add New Item context menu of the solution explorer, or the File>Add New Item menu.

Update 2: Updated typed collection to support design time environment, plus other fixes. version at link is to 1.1.0.

Cleaning the Visual Studio 2005 MRU list.

After playing with Visual Studio 2005 for a while, I have collected many a deal link in my most recently used items list. Unfortunately, VS2k5 always shows every item in the MRU list on the start page.

Well, I have updated my MRU list cleaner from 1.X to 2.0 with the November CTP. Here is what it looks like:


Get it here, includes source.

 

More Posts