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

My blog has moved. You can view this post at the following address: http://www.osherove.com/blog/2004/12/5/extending-nunit-easily-with-version-221-finally.html
Published Sunday, December 05, 2004 2:43 AM by RoyOsherove

Comments

Tuesday, December 07, 2004 4:54 AM by David Levine

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

Roy,

I wanted to try this out but ran into a snag...where can I get version 2.2.1 from? All that I can access on their web site is 2.2.0, and this does not support your classes. Thanks for any help

Tuesday, December 07, 2004 3:00 PM by Roy Osherove

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

David: My bad.
The 2.2.1 release not not a full release, but an iteration release.
As such it is hosted on the sourceforge site for nunit -

http://nunit.sourceforge.net

Wednesday, December 08, 2004 2:57 PM by David Levine

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

Thanks, that got me up and running. I tested this using v1.1 of the framework with v2.2.2 of nunit.

Ran into some interesting things when testing a method that throws an exception. Given a simple routine that throws an exception...

[Test]
[ExpectedException(typeof(ArgumentException),"Argument was false.")]
[SimpleTraceAttribute]
public void TestFail()
{
NeedsTesting testMe = new NeedsTesting();
Console.WriteLine("unitNeedsTesting.TestFail");
int rtn = testMe.DoSomethingThatNeedsTesting(false);
Assert.AreEqual(0,rtn,"Return value is incorrect.");
}


The trace attributes methods got called, but this consistently failed to pass the test even though it should have passed (i.e. the exception was thrown as expected). However, simply changing the order of the attributes to

[SimpleTraceAttribute]
[ExpectedException(typeof(ArgumentException),"Argument was false.")]

caused the test to pass, but now the SimpleTraceAttribute methods did not get called. So there's something weird in the way that nunit evaluates attributes.

Thursday, December 09, 2004 8:41 PM by TrackBack

# I changed my mind - Mock objects are wrong for database unit testing

Wednesday, December 15, 2004 7:03 PM by Jonas Beckman

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

Do you know if these attributes will work with the NUnit DLL (2.3.0) distributed with Testdriven? I really like Testdriven and also prefer the simplicity of one installer. But I suspect the Testdriven DLL isn't quite current (despite their version number). Have you had the chance to try?
Wednesday, December 15, 2004 8:34 PM by Roy Osherove

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

I don't think it willl...
I sent word to Jamie cansdale about this though...
Thursday, December 16, 2004 2:24 AM by Jonas Beckman

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

Thank you!

I play around with several NUnit DLL:s (and MBUnit etc) om my own machine, so I could probably get it to work there. But I am also managing two projects with several developers and existing unit tests. For them I try to provide the simplest possible development setup, so we can concentrate on writing tests.

Oh, I almost forgot... thank you for coming up with this really nice way of using attributes!
Sunday, December 19, 2004 9:50 PM by Charlie Poole

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

I've spent some time revising the way we do test case extensions. There are several problems with what's in 2.2.1 and 2.2.2.

1. As indicated in Roy's post above, you don't get the effect of any other attributes - not ExpectedException, not even Ignore - when you implement a test case extension on the model of the RepeatedTest example.

2. We have no way to indicate in what context a test case extension can play. Since some fixture extensions might be incompatible with a particlar test case extension, this is important.

I'm working on a new revision that will take care of these problems - for source code builders it should be available this week - for others, I'm not sure when the next release will be.