【发布时间】:2017-06-28 16:20:18
【问题描述】:
我正在使用以下测试方法测试DoingSomething() 方法-
[TestMethod()]
[ExpectedException(typeof(ArgumentException),"Invalid currency.")]
public void ConvertCurrencyTest_ExhangeRate()
{
try
{
DoingSomething();
}
catch (ArgumentException Ex)
{
}
catch (Exception Ex)
{
Assert.Fail();
}
}
测试结果显示DoingSomething() 没有抛出异常。但它确实引发了异常。
我错过了什么?
【问题讨论】:
-
您正在使用 try/catch 中的异常,因此它不会冒泡被测试捕获。
标签: c# unit-testing exception mstest