Wednesday, February 02, 2005 - 14:19

Unit Testing with nUnit

Okay, I'll come clean. I'm catching up on all the unit tests that I never got around to writing before, and as I hate writing unit tests, I keep thinking of things to blog about instead :-)

I see the usefulness of unit tests, and since I've been doing system testing I really appreciate them, but I still don't like writing them. And this is code that I wrote months and months ago, before we decided to do unit testing, so now it's a mission to go back and write comprehensive units tests for them. But I guess it has to be done at some point :-(

We're using nAnt (sorry, TestDriven.NET), and on the whole I'm pretty happy with it - I haven't used any other unit testing tools, so I don't know how it compares, but it works well enough for me. The one thing that does annoy me is that it doesn't have any support for exceptions. It should have something like:

ByteArray b = new ByteArray("AFX12");
Assert.ExceptionThrown(ArgumentException);

but instead you have to do something awkward like this:


bool ExceptionCaught = false;
try
{
b1 = new BitArray(bools);
}
catch (ArgumentNullException)
{
ExceptionCaught = true;
}
Assert.AreEqual(ExceptionCaught, true);

which is a lot more clumsy.

But enough delaying, back to the unit test writing :-(

Labels:

0 Comments:

Post a Comment

<< Home