如何在testNG中使用IAnnotationTransformer?
我调试时代码从未进入转换函数.它执行了所有3个测试.我使用Maven来触发我的测试,这就是我所拥有的 –
public class SomeTest {
@BeforeClass
public void before(){
TestNG testNG = new TestNG();
testNG.setAnnotationTransformer(new Transformer());
}
@Test(priority = 1)
public void test1(){}
@Test(priority = 2)
public void test2(){}
@Test(priority = 3)
public void test3(){}
}
public class Transformer implements IAnnotationTransformer {
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod){
if (true){
annotation.setEnabled(false);
}
}
}
最佳答案 在使用
serviceloaders进行设置之前,不会自动选择监听器.
根据需要,有多种方法可以指定侦听器.
如果您不想将它们应用于所有测试,则可以选择在单个类上应用侦听器
例如.
@Listeners(Transformer.class)
public class InterceptorTC {
@Test(priority..
您还可以从maven surefire插件中指定一个侦听器.阅读使用自定义侦听器部分here
指定侦听器的其他方法可以是在suite xml中定义它,并在maven插件中指定套件xml文件.
.