Mark Levison

Musings on No Touch Deployment, .NET development and photography

<September 2008>
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011


Navigation

Other

Blogroll

Subscriptions

Post Categories



Wednesday, June 16, 2004 - Posts

NUnit problems with Exceptions during FixtureTearDown

We're starting to add event subscriber leak testing to our unit tests. Some of our unit tests use FixtureSetup & FixtureTearDown to avoid incurring large expenses for test case (mock objects were just not suitable in these cases).

Now I run into the case where I need to detect the leaks (and throw an exception) during the FixtureTearDown but the exception gets caught by handleFixtureException and all that happens is the test suite turns yellow. However we need a test failure to stop our build, among other things.

Here is a pseudo-code example of what we're trying to achieve.


[TestFixtureSetUp]
Init() {
   expensiveObj = ExpensiveFactory.GetObject();
   originalSubscriberList = GetSubscriberList(expensiveObj);
   something = CreateSomethingWithListeners(expensiveObj);
}

Tests...

[TestFixtureTearDown]
Destroy() {
   something.Dispose();
   compare the originalSubscriberList to the current one and throw an Exception if
       their different.

   expensiveObj.Dispose();
}

Can anyone see a solution that doesn't require changes to the NUnit framework. The simplest solution I can think of is to create a special TestFixtureException and mark all the tests in that suite as failed.

Are there better options? Does NUnit 2.2 fix this?

posted Wednesday, June 16, 2004 7:15 PM by mlevison with 0 Comments




Powered by Dot Net Junkies, by Telligent Systems