Alex Rivera | Logout

Why doesn't Visual Studio break on exceptions when debugging unit tests?

Asked 2009-09-28T17:23:17.083
37

When I attempt to debug a unit test that fails because of an unhandled exception in my code, I expect Visual Studio to break on the unhandled exception so I can inspect the code and isolate the problem. Instead, the IDE instantly exits debug mode and the test is listed as "Failed", leaving me to consult the test result's stack trace to find the problem.

I've confirmed that the IDE is configured to break when any user-unhandled CLR exception is thrown. I can only get the expected behavior if I configure the IDE to break on all thrown exceptions. This, of course, makes normal debugging a PITA.

Am I out of luck?

Edit
Report

2 Answers

2

The unit testing framework handles the exception so visual studio thinks that the exception is handled.

answered 2009-09-28T17:26:22.990
-1

By default, even if you do a debug build, MSTest does't give you debugging (with break points, etc), unless you actually tell it to explicitly "Debug Unit Tests".

It should break on unhandled exceptions in Unit testing, provided you are in a Debug configuration, and you start the Unit Testing using "Debug" - ie: Using Ctrl+R, Ctrl+A instead of Ctrl+R, A to run all tests. In the testing window, there is a "Run" and a "Debug" menu with the options.

answered 2009-09-28T17:27:33.893

Your Answer