在TestNG中,您可以通过在方法中执行以下操作来禁用测试:
@Test(enabled = false)
我想知道是否有一种自动方式来清理整个套件,以便找到所有已启用设置为false的方法?
答案 0 :(得分:4)
您可以使用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);
}
}
}
答案 1 :(得分:0)
如果您不使用转换器就可以查看整个代码,则可以尝试使用我的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: ---------------------------------------------