views:

756

answers:

3

I currently trying to find a solution, how to ensure that a test fails if an exception occurs in a thread which is spawn by the test method.

I DON'T want to start a discussion about more than one thread in a unit test. => "unit test".Replace("unit","integration");

I already read a lot of threads in several forums, I know about CrossThreadTestRunner, but I'm searching for a solution whichs integrates into nunit, and does not require to rewrite a lot of tests.

A: 

I solved the problem by creating an addin for nunit, which "installs" an ITestDecorator.

Martin Moser
A: 

Hello Martin, can u please explain how do you solved the problem by using ITestDecorator. Thanks.

Chibacity! Thank you very much for your answer. I tried you solution with no success :(. NUnit GUI crashes when the thread exception occured. If somebody have another solution, please let me know.

Hicham Benkirane
+1  A: 

The reason that exceptions on non-test threads (i.e. other spawned threads) do not cause tests to fail is that NUnit is configured by default to use legacyUnhandledExceptionPolicy which is a .Net process level setting which can be applied via app.config, i.e.:

<legacyUnhandledExceptionPolicy enabled="1"/>

Enabling this setting (i.e. setting it to "1") causes exceptions which do not occur on the main thread to be ignored.

I wrote an article which goes into more detail in reference to this issue with the ReSharper test runner, but it applies equally to the NUnit test runner:

http://gojisoft.com/blog/2010/05/14/resharper-test-runner-hidden-thread-exceptions/

chibacity