为什么在调试单元测试时Visual Studio不会中断异常? [英] Why doesn't Visual Studio break on exceptions when debugging unit tests?

查看:330
本文介绍了为什么在调试单元测试时Visual Studio不会中断异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试调试由于代码中未处理的异常而失败的单元测试时,我希望Visual Studio能够打破未处理的异常,以便我可以检查代码并隔离问题。相反,IDE会立即退出调试模式,测试列为失败,让我查阅测试结果的堆栈跟踪以找到问题。

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.

确认IDE被配置为在抛出任何用户未处理的CLR异常时中断。如果我配置IDE以破坏所有抛出的异常,我只能得到预期的行为。这当然是正常的调试PITA。

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.

我运气不好吗?

推荐答案

为什么你的异常不是未处理的原因。单元测试框架正在处理引擎盖下的异常并将其转换为故障。

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.

您需要做的是打破抛出的异常。如果您将此功能与启用仅我的代码(默认情况下)相结合,则应该获得您期望的行为。当您的代码发生异常时,Visual Studio将只会中断。

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.

这篇关于为什么在调试单元测试时Visual Studio不会中断异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆