Thursday, May 13, 2004

Moving from NUnit to MbUnit -- here goes nothing

With some encouragement from my first ever Blog Comment (thank you Jonathan) I'm trying to convert from NUnit to MbUnit. I figure I'd document as I go.

Having dropped the latest version of MbUnit onto my VPC I figure I'd load some existing assemblies to see what happens when using the MbUnit GUI against an NUnit assembly.

First, add an assembly. Hang on... no menus. I had a brain-blip. For a second or two (I hope it was only that long) I couldn't figure out just what to do. Thankfully my well trained right-mouse-button-index-finger jumped in and pulled me out of my haze. Of course, the context menu. Where was I again? [Is it time for my pudding?]

Oh, yes, adding assemblies. Adding my previously compiled assembly gave me a security exception. I guess this isn't too much of a surprise as I'm developing as a non-admin. In particular it was a security error from Microsoft.ApplicationBlocks.ExceptionManagement trying to access the registry. Cool thing is, this error "went away." Okay so I cheated. I ran the app as an admin, then I ran as my user again.

Running a second time I get a different error (progress, no?) It's a System.BadImageFormatException. I know this one. Since I'm running the .NET 1.1 binary on a Whidbey/CTP2005/.NET 2.0 machine it tips over. I can deal with that. Just as the following line to the MbUnit.GUI.exe.config
        <supportedRuntime version="v2.0.40301" />

Okay, third times a charm right. Not quite. The app runs. Adding assemblies appears to be working but nothing happens. Running tests does nothing. Removing assemblies does nothing.

Let's try recompiling with MbUnit...

First removing all references to NUnit.Framework; easy enough.
Add references to MbUnit.Framework.dll. You'll need MbUnit.Core.dll too.
Replace using NUnit.Framework; with using MbUnit.Framework; (for TestFixtureAttrbite a.k.a [TestFixture]) AND using MbUnit.Core.Framework; (for TestAttribute a.k.a [Test])

This probably would've been all that's required except that I have some custom NUnit type assert code for things that NUnit missed like AreEqual methods for System.Xml and System.Xml.XPath. So for that there were a bunch of code changes required. I can't help but notice the MbUnit.Core.Framework.Xml namespace. Perchange my custom stuff can go by-by?

BTW: If you aren't using Lutz Roeders amazing .NET Reflector why don't you? Developing in .NET with it is like a kybrd wtht vwls.

So far, so good. I have an assembly.

WooHoo. I'm able to run the tests. A few aren't working, but hey, I changed some code and replace the whole unit testing framework. 2 failures out of 64 tests isn't too bad (I'll look at those later.)

There's a few hiccups with the GUI (loading multiple assemblies caused some grief) but it mostly worked. And the HTML report is sweeet. Once I get the kinks ironed out I'll post again.

That's all for now. Got to get some sleep for my day job. Sigh.

[Listening to: Rob Zombie - Return of the Phantom Stranger]

3 comments:

Anonymous said...

Hi,

Sorry about the "experimentalness" of MbUnit but it is still a young application. I should write a little article on using the GUI.

I'm currently working with Jamie Cansdale to integrate MbUnit into NUnitAddIn so you will be able to run the tests inside VS. In fact, MbUnit will load the NUnit,csUnit fixture as well. No need to change the references. If you are not using NUnitAddIn, you should give it a try. It is really an exceptional add-in! It lets you select a namespace/class/method and run it with NUnit,CsUnit, or the debugger.

Now some tips for you:

- You can try XmlAssert ( in MbUnit.Core.Framework), which is a port of XmlUnit into MbUnit,
- There are lots of others "specialized" assertion classes like: StringAssert, RefleAssert, ColAssert, etc...

Jonathan de Halleux

Anonymous said...

How do I call MBUnit form the command line to generate the test reports?

BigEasy said...

I've never tried MbUnit from the command line -- I've always used the GUI (right click is your friend, repeat after me, right click IS YOUR _FRIEND_)

I'd recommend hopping over to Jonathan de Halleux must-read blog at: http://blog.dotnetwiki.org/ A post there should get into the right hands.

-Dave Montgomery