2
我測試DoingSomething()
方法與下面的測試方法 -處理單元測試預期的例外MSTest的
[TestMethod()]
[ExpectedException(typeof(ArgumentException),"Invalid currency.")]
public void ConvertCurrencyTest_ExhangeRate()
{
try
{
DoingSomething();
}
catch (ArgumentException Ex)
{
}
catch (Exception Ex)
{
Assert.Fail();
}
}
測試結果表示,DoingSomething()
沒有拋出異常。但它確實引發了異常。
我在這裏錯過了什麼?
您正在使用try/catch中的異常,因此它不會冒泡被測試捕獲。 – Nkosi