因为我有这么多测试,如果我能以某种方式检查是否有任何"启用=假"的测试,以消除"遗忘&#34的风险将是非常有帮助的。 ;再次启用测试
所以我需要这样的东西 - >检查禁用的测试
我已经创建了一个超级测试类,有没有办法检查子类中的禁用测试?
答案 0 :(得分:1)
测试方法配置覆盖了类配置。
所以,如果你有两个:
@Test(enable = false)
public class MyTest {
@Test
public void test() {}
}
然后将启用测试,因为enable
的默认值为true
。
如果您想恢复逻辑,解决方案是使用IAnnotationTransformer
中的https://github.com/cbeust/testng/pull/816/
public class TestClassDisabler implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,
Method testMethod) {
if (testMethod != null) {
Test test = testMethod.getDeclaringClass().getAnnotation(Test.class);
if (test != null && !test.enabled()) {
annotation.setEnabled(false);
}
}
}
}
答案 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: ---------------------------------------------