I’m testing the code which starts a secondary thread. And this thread sometimes throws an exception. I’d like to write a test which fails if that exception isn’t handled properly.
I’ve prepared that test, and what I’m seeing in NUnit is:
LegacyImportWrapperTests.Import_ExceptionInImport_Ok : PassedSystem.ArgumentException: aaaaaaaaaa
at Import.Legacy.Tests.Stub.ImportStub.Import() in ImportStub.cs: line 51...
But the test is marked as GREEN. So, NUnit knows about that exception, but why does it mark the test as Passed?
That you can see the exception details in the output does not necessarily mean that NUnit is aware of the exception.
I have used the
AppDomain.UnhandledExceptionevent to monitor scenarios like this during testing (given that the exception is unhandled, which I assume is the case here):If you want to test only for specific exceptions you can do that in the event handler: