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
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.
I found a solution that works for me in a similar scenario.
If you notice that the debugger output is throwing handled exceptions you can note those exceptions.
Example
Take the ones you've just noted and open up the Exception Settings
Alternatively you can hit Ctrl+Alt+E
From there you'll see a number of specific exceptions you can enable your IDE to break on.
For example: ArgumentNullException
This is caused because by the fact that the tests are run using MSTest (with Visual Studio used simply as a shell). MSTest will mask these exceptions that are being thrown and they will never bubble up to Visual Studio. If you run the tests in debug mode it should work.
If you right click the test(s) in Test View and choose to debug them, it should run the code through the IDE and exceptions should break appropriately.
This did the trick for me:
Ctrl + Alt + E for Exceptions menu -> Press Reset All
Go to: Tools -> Options -> Debugging -> General: you need to make sure both "Enable Just My Code" and "Enable the exception assistant" are checked.
The unit testing framework handles the exception so visual studio thinks that the exception is handled.
The reason why is that your exceptions are not unhandled. The unit testing framework is handling the exceptions under the hood and converting them to failures.
What you need to do instead is to break on thrown exceptions. If you combine this with enabling "Just My Code" (on by default) you should get the behavior you are expecting. Visual Studio will only break when exceptions thrown by your code occur.