【问题标题】:How to skip or ignore execution of tests in TestNG如何在 TestNG 中跳过或忽略测试的执行
【发布时间】:2016-02-02 07:10:31
【问题描述】:

我正在使用 TestNG 在 java 中编写测试。

我想在类文件中使用条件跳过或忽略所有类方法。

在 ruby​​ 中,我关注了这个How to skip certain tests with Test::Unit

在java中我该怎么做?

【问题讨论】:

    标签: java testng


    【解决方案1】:

    如果假设不成立,您可以在测试中抛出SkipException,并且该机制足够灵活,甚至可以将测试标记为已跳过或失败。 This article 展示了如何以声明的方式将这种方法集成到您的测试套件中。基本上你用@Assumes注释方法并有一个自定义IInvokedMethodListener

    或者(我不鼓励这样做,但这是一个选项),如果您可以确定要静态跳过的内容,您可以动态生成 XML 规范并运行它。

    【讨论】:

      【解决方案2】:

      另一种解决方案是使用IAnnotationTransformers,然后像使用@Test(enabled = false) 一样禁用测试。

      public void transform(ITest annotation, Class testClass,
            Constructor testConstructor, Method testMethod) {
          if (...determine if the test should be disabled) {
              annotation.setEnable(false);
          }
      }
      

      【讨论】:

        【解决方案3】:

        你可以使用注解@Test(enabled = false)忽略测试方法

        【讨论】:

          猜你喜欢
          • 2015-02-02
          • 1970-01-01
          • 2017-01-26
          • 1970-01-01
          • 1970-01-01
          • 2020-01-01
          • 2020-01-21
          • 2020-12-07
          • 2018-11-26
          相关资源
          最近更新 更多