Mark Levison

Musings on No Touch Deployment, .NET development and photography

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Other

Blogroll

Subscriptions

Post Categories



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 on Wednesday, June 16, 2004 7:15 PM by mlevison





Powered by Dot Net Junkies, by Telligent Systems