有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在没有断言的情况下可以跳过/忽略Cumber测试用例。假设(……)

我有黄瓜。具有多个测试用例的功能文件(使用“示例”)
在某些情况下,我想跳过几个测试用例,只运行其中的几个

注意: 用户应该能够选择动态跳过哪个测试用例 例如,他可以在第一次运行时决定跳过第1个测试用例,下次决定跳过第2个

Examples:
  | SERIAL_NO | ID                |
  | 1         | Create-Customer A |
  | 2         | Create-Customer B |
  | 3         | Create-Customer C |

我设法用电脑做了那件事

Assume.assumeTrue(...)

唯一的问题是-code抛出异常,我希望保持日志清晰

是否有任何选项可以避免打印异常,而忽略测试用例? 或者用另一种解决方案跳过它

谢谢


共 (2) 个答案

  1. # 1 楼答案

    最后,我找到了一个简单的解决方案,使用了与我前面提到的Assert相同的方法。假设(…),只需清除异常堆栈跟踪,然后重新抛出它

    在下面的代码中,您可以看到实际的更改只是我添加了catch块:

    try
    {
        Assume.assumeTrue("Some Condition...");
    }
    catch (AssumptionViolatedException e)
    {
        // clearing stack trace, so it will keep logs clear, just print the name of exception
        e.setStackTrace(new StackTraceElement[] {});
        throw e;
    }
    

    现在,异常堆栈跟踪未打印到日志,因此日志保持干净,我只看到以下内容:

    org.junit.AssumptionViolatedException: got: <false>, expected: is <true>

    这对我来说已经足够好了

  2. # 2 楼答案

    我会将您的示例分成每个场景,其中您希望跳过测试并使用@todo标记,如下所示:

       Scenario Outline: [test-scenario-001] Send a new form with request type  
       Given I preload the from using "request"
       And I select the 'Submit' button
       Then the response message "hello" is returned
       Examples:
        | request |
        | POST    |
       @todo
       Examples:
        | request | 
        | GET     |
        | PUT     |
        | DELETE  |
    

    然后,要仅为第一个Example运行场景,请调用标记not to run作为功能的一部分:

    -Dcucumber.options=" tags ~@todo"
    

    要运行所有Example场景,请不要使用标记