VS 2010,编码的UI测试:重新运行失败的测试用例

Jul*_*lia 3 testing automation visual-studio-2010 coded-ui-tests

我正在使用VS2010 Premium,编码的UI测试.

你知道如何在运行后重新执行失败的测试用例吗?如果在重新执行后传递了测试,那么它应该在结果报告中传递.

cha*_*sos 5

不是那么优化的方法,但try/catch如果抛出异常,您可以将所有代码阻塞并重新运行测试:

[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();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)