Follow @RoyOsherove on Twitter

A cool macro to ease your NUnit boilerplate woes

Havn't checked this out myself yet, but it seems like something to write home about.

Very nice macro was posted that makes NUnit boilerplate code creation faster, and i've just discovered it:

 

I've created a Visual Studio.NET macro for creating NUnit tests, in vsmacros format and exported to VB.  The nice thing about the macro is that it's easier to preserve existing code and it also integrates well with the VS.Net project and solution files.  The macro creates unit test shells for the active file in the IDE as follows:

  1. It creates a subproject "UnitTests" under your main solution.
  2. For each class declared in the file, the macro creates a file and namespace based upon the full name of the class being tested.  For example, if the class you're creating tests for is called "MyCo.MyLib", then the macro will generate a file named "MyCo.MyLib_UnitTests.cs" containing a namespace named "MyCo.MyLib_UnitTests".  Test cases aren't generated for abstract classes or classes that otherwise can't be instantiated, or that have no public members.
  3. For each method, property, event and field in the class, the macro generates a test case in the test namespace based on the member name.  For example, a method Foo gets a TestCase named "TestFoo".  The macro also generates some boilerplate setup and teardown code and a class member of the type of the object being tested that gets initialized in setup.  If the object being tested implements IDisposable, then TearDown will contain a call to Dispose(). 
  4. The macro is compatible with NUnit 2.0 and backwards compatible with NUnit 1.0.  If you're still using NUnit 1.0, edit the macro and find the line that says
    #Const NUNIT2 = True

...

This macro is licensed under the same license as NUnit 2.0.

 

[via Gordon & Karyn Weakliem's home page]

Looks great! Here's the direct link to the actual macro : Get it here
Iv'e dicovered this through one of 
links on .Net Rocks. which i will hopefully write about 
in a later post..
 
 

Custom Attributes are goodness

Joke