Re: Expected Unhandled Exceptions
"Charlie Poole" <[email protected]> Fri, 11 Jul 2008 12:42:19 -0700
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <007801c8e38e$3da60210$6401a8c0@ferrari> |
This is a knotty problem and goes a bit beyond what most would call unit testing. If I understand rightly, you want to test that 1) An exception is thrown, 2) That it is caught by the unhandled exception handler. Since the test is passing, I assume that you are creating a thread - or your SUT is creating one. I say that because it's impoissilbe to have an unhandled exception in the test without creating a thread, since NUnit handles all exceptions on the test thread. I was surprised to hear that the exception was being handled correctly by your handler, since I was under the impression that an unhandled exception handler had to be in the primary appdomain to work. It turns out - as you probably know - that MS changed that beginning with 2.0. Per the documentation for AppDomain.UnhandledExceptionEvent, your unhandled exception should be reported to a handler in the domain where the thread was created and /also/ to the handler in the primary AppDomain, which is created by NUnit. That's exactly what you seem to be seeing. Your handler takes care of things, so the test passes, but NUnit's handler also gets the exception. Since NUnit has no way to know that you already took care of the exception, it reports it. Unfortunately, I don't see any way around this, but I'm open to suggestions. Charlie _____ From: [email protected] [mailto:[email protected]] On Behalf Of Wade Barnes Sent: Friday, July 11, 2008 9:20 AM To: [email protected] Subject: [Nunit-users] Expected Unhandled Exceptions Hi, Is there any way to tell a particular test to expect an unhandled exception; one that would normally be indicated through the AppDomain.UnhandledException event? I am testing code that uses AppDomains to isolate code. One of the tests purposely causes an unhandled exception in one of these AppDomains to ensure it is properly reported and acted upon by the code managing the AppDomains; therefore I am expecting an unhandled exception to occur. The issue: The test itself passes. However, When using the GUI runner the test bar goes Red and the unhandled exception is reported in the output list. When using the Console runner this same unhandled exception causes the runner to return a code of -100; this ends up failing our nightly build. What I would like to do: I would like to be able to indicate, for a particular test, that an unhandled exception is expected. I would then expect the test to behave similarly to any other test expecting an exception; if received it happy goes about the remained of its testing business, otherwise it fails because it did not receive the expected exception. Additionally when such a test is encountered I would expect the test bar in the GUI not to turn Red and the unhandled exception not to be reported in the output list; similarly I would expect the Console runner not to return -100. Wade ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ Nunit-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nunit-users