为什么在调试单元测试时Visual Studio不会中断异常?

编程入门 行业动态 更新时间:2024-10-23 13:22:37
本文介绍了为什么在调试单元测试时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不会中断异常?

本文发布于:2023-11-08 13:41:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569531.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   异常   Visual   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!