如何prevent预期的例外情况打破了调试试运行? [英] How to prevent expected exceptions from breaking the debug test run?
本文介绍了如何prevent预期的例外情况打破了调试试运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当在调试模式下运行MSTEST单元测试,执行停止在被抛出的每一个预期的异常。我的测试看起来像这样
[TestMethod的()
[ExpectedException(typeof运算(ArgumentNullException))]
公共无效ShouldThrowExceptionWhenPassingNull()
{
对象数据= NULL;
target.CheckNull(数据);
}
目标的方法是这样的:
公共无效CheckNull(对象数据)
{
如果(的ReferenceEquals(空,数据))
{
抛出新ArgumentNullException(数据);
}
} //试运行这里休息:ArgumentNullException是未处理由用户code
解决方案
你有没有尝试使用运行测试 CTRL-R CTRL-T
而不是 CTRL-R牛逼
?参阅参考此的链接。
编辑 如果它不是一个键盘快捷键的问题,然后检查<一href="http://social.msdn.microsoft.com/Forums/en/vsdebug/thread/25bdf149-5133-4f47-bbf2-1d4ca638fee9">this链接。你可以尝试以下的说明有:
对于异常类型
- 禁用用户未处理的异常中断 你,你遇到这里(通过 调试 - >例外)
所有异常- 在禁用用户未处理的异常中断(通过 调试 - >例外)
- 禁用只是我的code
When running MSTEST unit tests in debug mode, the execution stops in every expected exception that is thrown. My test looks like this
[TestMethod()]
[ExpectedException(typeof(ArgumentNullException))]
public void ShouldThrowExceptionWhenPassingNull()
{
object data = null;
target.CheckNull(data);
}
the target method looks like this:
public void CheckNull(object data)
{
if (ReferenceEquals(null, data))
{
throw new ArgumentNullException("data");
}
} // test run breaks here: ArgumentNullException was unhandled by user code
解决方案
Did you try running the tests using ctrl-R ctrl-T
instead of ctrl-R T
? Refer to this link for reference.
EDIT If it's not a keyboard shortcut issue, then check out this link. You could try the following as noted there:
- Disable "break on user unhandled exceptions" for the exception types you you are encountering here (via Debug -> Exceptions)
- Disable "break on user unhandled exceptions" for all exceptions (via Debug -> Exceptions)
- Disable "Just My Code"
这篇关于如何prevent预期的例外情况打破了调试试运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文