Immediate - Ad Hoc Tests

Okay, as promised I've implemented Ad Hoc tests in the latest build. The idea is to allow any method to be used as an Ad Hoc test. If the class the method belongs to implements a constructor or the IDisposable interface, these will be used to set up and tear down the test (unless the method is static). If the method returns an object, its fields and properties will be displayed (in a similar format the the Immediate window).

using System;

using System.Diagnostics;

///

/// Any class with a default constructor can be used as an Ad Hoc test fixture.

/// Target an individual method to run as a test and dump returned object (if any).

///

class AdHoc : IDisposable

{

// SetUp using default constructor.

private AdHoc()

{

Trace.WriteLine("SetUp");

}

 

// Dump the fields and properties of any returned complex object.

public AppDomain TestComplex()

{

return AppDomain.CurrentDomain;

}

 

// Enumerate the values of any returned object implementing IEnumerable.

public string[] TestEnumerable()

{

return new string[] {"Test1", "Test2", "Test3"};

}

 

// Test methods can be private and/or static.

private static string TestPrivateStatic()

{

return "No SetUp or TearDown for static methods";

}

 

// TearDown using IDisposable interface.

void IDisposable.Dispose()

{

Trace.WriteLine("TearDown");

}

}

Note: The 'New Project...' wizards aren't showing up in Visual Studio.NET 2003 Beta. Using Ad Hoc tests will be an easy way of giving the addin a spin.

No Comments