---
title: "Extending NUnit *easily* with version 2.2.1 (finally!)"
url: "https://osherove.com/blog/2004/12/5/extending-nunit-easily-with-version-221-finally.md"
canonical: "https://osherove.com/blog/2004/12/5/extending-nunit-easily-with-version-221-finally.html"
published: "2004-12-05T00:43:00"
updated: "2004-12-05T00:43:00"
tags: [".Net Original", "Agile Related"]
author: "Roy Osherove"
description: "I finally got some time so I sat down with the latest version of NUnit - 2.2.1 and tried using its extensibility features like the ability to create new custom test attributes that change test behavior, hopefully…"
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/"
---

# Extending NUnit \*easily\* with version 2.2.1 (finally!)

By Roy Osherove December 5, 2004 In [.Net Original](https://osherove.com/blog/category/net-original), [Agile Related](https://osherove.com/blog/category/agile-related)

**Historical article** · Originally published December 5, 2004; technical details may be outdated.

I finally got some time so I sat down with the latest version of [NUnit](http://www.nunit.org/) \- 2.2.1 and tried using its extensibility features like the ability to create new custom test attributes that change test behavior, hopefully ridding myself of more complex projects that I had to do in the past _(such as using interception or create a whole new binary version of Nunit just so that this could be done)_ .

I'm glad to say that it worked out **great**! NUnit 2.2.1 finally allows one to (no so)easily add custom attributes such as Rollback to NUnit without resorting to violence. Yey!

Unfortunately, the process is still too bureaucratic (for me at least), requiring the developer to add 3 new classes for each test attribute. I took it upon myself to check and see if this process could be made easier and it does :)

I basically created a base class you inherit from and does all the nasty work for you. Here's how easy it is to create a new attribute that does tracing on your unit tests:

---

\[AttributeUsage(AttributeTargets.Method, AllowMultiple\=false)\]

\[TestBuilder(typeof(CustomTestAttributeBase.CustomTestBuilder))\]

public class SimpleTraceAttribute:CustomTestAttributeBase

{

   public override void BeforeTestRun (TestCaseResult testResult,

                                       TemplateTestCase testCase)

            {

                  Console.WriteLine("START: "\+ testCase.Name);

            }

   public override void AfterTestRun (TestCaseResult testResult,

                                    TemplateTestCase testCase)

            {

                  Console.WriteLine("END: "\+ testCase.Name);

            }

}

---

Simple and quick, no fuss.

[Read this article for the nasty details and code you can use](http://weblogs.asp.net/rosherove/articles/ExntendingNunit221.aspx)

## More in .Net Original

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

- Dec 13, 2004

    ### [Juval Lowey in Israel](https://osherove.com/blog/2004/12/13/juval-lowey-in-israel.html)

- Dec 9, 2004

    ### [More free cool components from SharpTools](https://osherove.com/blog/2004/12/9/more-free-cool-components-from-sharptools.html)

- Dec 2, 2004

    ### [The Regulator sucks for Non-Admins](https://osherove.com/blog/2004/12/2/the-regulator-sucks-for-non-admins.html)

- Nov 24, 2004

    ### [My TDD webcast yesterday was pretty fun](https://osherove.com/blog/2004/11/24/my-tdd-webcast-yesterday-was-pretty-fun.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/
