我正在使用 VS2010 Premium,编码的 UI 测试。
你知道如何在运行后重新执行失败的测试用例吗? 如果重新执行后测试通过,则应在结果报告中通过。
最佳答案
不是最佳方式,但您可以将所有代码放入 try/catch
block 并在抛出异常时重新运行测试:
[CodedUITest]
public class CodedUITest
{
private static int _maxTestRuns = 5;
[TestCleanup]
public void Cleanup()
{
//If the test has reached the max number of executions then it is failed.
if (_maxTestRuns == 0)
Assert.Fail("Test executed {0} times and it was failed", _maxTestRuns);
}
[TestMethod]
public void CodedUITestMethod()
{
try
{
this.UIMap.RecordedMethod1();
}
catch (Exception exception)
{
//Call Cleanup, rerun the test and report the error.
if (_maxTestRuns > 0)
{
_maxTestRuns--;
TestContext.WriteLine(exception.Message);
TestContext.WriteLine("Running Again...");
this.Cleaup();
this.CodedUITestMethod();
}
}
}
}
关于visual-studio-2010 - VS 2010,编码的 UI 测试 : Re-run failed test cases,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11801006/