---
title: "A cool macro to ease your NUnit boilerplate woes"
url: "https://osherove.com/blog/2003/3/9/a-cool-macro-to-ease-your-nunit-boilerplate-woes.md"
canonical: "https://osherove.com/blog/2003/3/9/a-cool-macro-to-ease-your-nunit-boilerplate-woes.html"
published: "2003-03-09T13:37:00"
updated: "2003-03-09T13:37:00"
tags: [".Net Quotations", "Tips & Tricks"]
author: "Roy Osherove"
description: "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…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# A cool macro to ease your NUnit boilerplate woes

By Roy Osherove March 9, 2003 In [.Net Quotations](https://osherove.com/blog/category/net-quotations), [Tips & Tricks](https://osherove.com/blog/category/tips-tricks)

**Historical article** · Originally published March 9, 2003; technical details may be outdated.

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

Very nice macro was [posted](http://www.pcisys.net/~gweakliem/Gordon/UnitTesting.html) that makes NUnit boilerplate code creation faster, and i've just discovered it:

_I've created a Visual Studio.NET macro for creating_ [**_NUnit_**](http://nunit.sourceforge.net/) _tests, in_ [**_vsmacros format_**](http://www.pcisys.net/~gweakliem/Gordon/UnitTest.vsmacros) _and exported to_ [**_VB_**](http://www.pcisys.net/~gweakliem/Gordon/UnitTestGeneration.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..
 
 
```

## More in .Net Quotations

[All posts in .Net Quotations](https://osherove.com/blog/category/net-quotations)

- Apr 16, 2003

    ### [CLR tips gold mine detected](https://osherove.com/blog/2003/4/16/clr-tips-gold-mine-detected.html)

- Apr 11, 2003

    ### [ASP.NET Encoding Tip from Scott Hanselman](https://osherove.com/blog/2003/4/11/aspnet-encoding-tip-from-scott-hanselman.html)

- Mar 5, 2003

    ### [Explorer Tips and tricks for the keyboard junkie](https://osherove.com/blog/2003/3/5/explorer-tips-and-tricks-for-the-keyboard-junkie.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
