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?