当在调试模式下运行MSTEST单元测试,执行停止在被抛出的每一个预期的异常。我的测试看起来像这样
[TestMethod的()
[ExpectedException(typeof运算(ArgumentNullException))]
公共无效ShouldThrowExceptionWhenPassingNull()
{
对象数据= NULL;
target.CheckNull(数据);
}
目标的方法是这样的:
公共无效CheckNull(对象数据)
{
如果(的ReferenceEquals(空,数据))
{
抛出新ArgumentNullException(数据);
}
} //试运行这里休息:ArgumentNullException是未处理由用户code
解决方案
你有没有尝试使用运行测试 CTRL-R CTRL-T
而不是 CTRL-R牛逼
?参阅参考此的链接。
编辑 如果它不是一个键盘快捷键的问题,然后检查this链接。你可以尝试以下的说明有:
对于异常类型禁用用户未处理的异常中断 你,你遇到这里(通过 调试 - >例外) 所有异常在禁用用户未处理的异常中断(通过 调试 - >例外) 禁用只是我的codeWhen 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"