【问题标题】:Is there anyway to find all tests that are disabled in a TestNG suite?无论如何可以找到在 TestNG 套件中禁用的所有测试?
【发布时间】:2016-10-10 14:55:36
【问题描述】:

在 TestNG 中,您可以通过在方法中执行以下操作来禁用测试:

@Test(enabled = false)

我想知道是否有一种自动清理整个套件的方法,以便找到所有已启用设置为 false 的方法?

【问题讨论】:

  • 您可以在项目中搜索该特定字符串@Test(enabled = false)。这将向您显示使用它的每个实例。
  • 如何在 IDE 中执行此操作? (我正在使用 Eclipse)
  • CTRL + ALT + G.
  • 这对你有用吗?
  • 是的@Brian,谢谢

标签: java testing automation testng


【解决方案1】:

您可以使用IAnnotationTransformer

public class MyTransformer implements IAnnotationTransformer {

  public void transform(ITest annotation, Class testClass, Constructor testConstructor, Method testMethod) {
    if (!annotation.getEnabled()) {
      System.out.println(testClass != null ? testClass : testMethod);
    }
  }
}

【讨论】:

    【解决方案2】:

    如果你想在不使用转换器的情况下查看整个代码,你可以试试我的dedicated library

    @Listeners(DisabledTestsListener.class)
    public class InventoryTests {
    
        @Test
        @DisabledTestsCollector(testsPath = "/src/test/java")
        void getDisabledTest() {
            // This test would collect all disabled tests in TestNG project.
        }
    

    输出示例:

    Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener afterInvocation
    INFO: You have 2 disabled TestNG tests in your project.
    Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener afterInvocation
    INFO: ---------------------------------------------
    Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener lambda$afterInvocation$0
    INFO:  firstDisabledTest is a TestNG test which currently disabled.
    Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener lambda$afterInvocation$0
    INFO: ---------------------------------------------
    Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener lambda$afterInvocation$0
    INFO:  secondDisabledTest is a TestNG test which currently disabled.
    Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener lambda$afterInvocation$0
    INFO: ---------------------------------------------
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      • 1970-01-01
      • 2013-10-09
      • 2020-12-17
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多