停止测试&标记为已完成(测试期间)

时间:2018-03-27 13:27:29

标签: c# coded-ui-tests

我正在寻找CUI-Tests通过命令停止测试的方法,但是返回测试已成功完成。 例如:

if (something)
{
   //Code
}
else
{
   //Test should be aborted here; but marked as Completed
}

提前致谢!

1 个答案:

答案 0 :(得分:1)

一个简单的机制是将测试方法的主体移动到辅助方法中,并让主测试方法调用该帮助程序。每当测试需要退出并且测试通过时,只需执行return。代码看起来如下所示:

[TestMethod]
public void CodedUITestMethod1()
{
    CodedUITestMethod1Helper();
}

public void CodedUITestMethod1Helper()
{
    ... some test code ...;

    if (something)
    {
       ... more test code ...;
    }
    else
    {
       // Test is aborted here; but marked as Completed
       return;
    }

    ... some test code ...;

    if (something else)
    {
       ... more test code ...;
    }
    else
    {
       // Test is aborted here; but marked as Completed
       return;
    }

    ... some test code ...;
}