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

后端 未结 8 746
深忆病人
深忆病人 2020-12-29 02:53

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

8条回答
  •  猫巷女王i
    2020-12-29 03:24

    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.

提交回复
热议问题