testng IAnnotationTransformer在运行时禁用测试时不评估条件

时间:2017-07-13 09:16:52

标签: selenium testng

我的代码如下所示:

public class A implements IAnnotationTransformer {

@BeforeClass(alwaysRun = true)
    public void setUpBeforeClass() throws Exception {
        TestNG testNG = new TestNG();
        testNG.setAnnotationTransformer(new A());
}

@Test
public void testA() throws Exception {
//do some steps and evaluate condition "toBeSkipped" , which results in 
//either "true" or "false" string values.
}

@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
        if ("testA".equals(testMethod.getName())) {
            if ( !toBeSkipped.equalsIgnoreCase("true")) {
                annotation.setEnabled(false);
            }
        }
    }

}

我在testng.xml中提到了监听器。

问题 - 当我开始测试时,它不会执行测试方法" testA()"首先,但首先转到transform()方法并在行#34; !toBeSkipped.equalsIgnoreCase("true")"上抛出nullPointer异常。陈述" toBeSkipped" flag为null。这是因为它没有评估条件,因为它没有执行测试。

0 个答案:

没有答案