【发布时间】:2015-08-24 14:43:42
【问题描述】:
我有一个带有一个按钮的窗口窗体,我正在尝试使用 codedUitest 对其进行测试。如果抛出任何异常,我希望测试失败,但在测试类中它不会捕获异常。
这是我的代码:
public void button1_Click(object sender, EventArgs e)
{
double[] dummy = new double[1];
int i = 1;
if (i > 0)
{
throw new System.IndexOutOfRangeException("index parameter is out of range.");
}
else
{
dummy[i] = 6;
}
}
测试方法是:
public void CodedUITestMethod1()
{
try
{
this.UIMap.TryBtn1();
}
catch (IndexOutOfRangeException)
{
Assert.Fail();
}
}
【问题讨论】:
-
查看这篇文章在单元测试中捕捉异常stackoverflow.com/questions/933613/…
-
你使用什么单元测试框架?
-
stackoverflow.com/questions/8381042/… 很好,但我想在包含很多方法的应用程序上使用它,向每个方法添加 try catch 块没有意义,我使用的是 .NET Framework 4.5
标签: c# exception-handling coded-ui-tests