Introducing: XtUnit . An Unofficial Unit Testing Extensibility Framework - Add new attributes to NUnit or MbUnit easily!
Tuesday, October 5, 2004 at 7:26PM
Roy Osherove in .Net Original, Agile Related

Update: I've uploaded a more complete version of the framework and also changes the file name. please get it from here:

http://www.teamagile.com/downloads/TeamAgile.XtUnit.Bin.zip

http://www.teamagile.com/downloads/TeamAgile.XtUnit.src.zip

if you have the earlier version.  (and just so you know - it works perfectly with the TestDriven.Net tool suite)


 

One of the things that have bothered me the most since I got into the whole "Add database rollback to your unit tests" thing, is how much work it takes to make your test suite use this feature. I actually went and made a new binary of the NUnit Framework to support this new attribute. All this because there is no clear extensibility model for NUnit these days. Peli, on the other hand has a very nice way of extending MbUnit, but it still entails recompiling his library for this to work (or am I wrong?)

so - an idea came to me. A while ago Peli told me he had just found out about ContextBoundObjects and the ability to "intercept" method calls for pre and post processing. He said it might have some cool things that can be used with unit testing but we couldn't find something that was really cool to do with it.

The other day, while reading this nice article about implementing interception in your code, I got an idea: Maybe interception and Contexts are the best way for extensibility? So, I gave it a shot. And it turns out pretty darn cool I have to say.

Introducing the XtUnit.Framework project

With this project you are now able to add any attribute you can think of to you NUnit (or any other xUnit tests) with the ease of simply deriving from a base class. In the solution that you can download you will find 3 projects:

now here are the cool things:

 

I'd love to get your feedback. Have fun :)

I'd like to thank Jamie for helping me solve two simple and annoying bugs I just couldn't find with my thick head.

Article originally appeared on Osherove (http://osherove.com/).
See website for complete article licensing information.