我有一个实现IAnnotationTransformer, IInvokedMethodListener, ITestListener and IReporter
的侦听器类。
我的测试成功运行但是我收到警告"[TestNG] [WARN] Ignoring duplicate listener : com.NGtest.RetryListener"
。每个方法调用都会显示此警告,即每次测试方法调用多次调用Listener,因此 IGNORED重复警告。
IReporter
实施,则警告消失。听众类:
public class RetryListener implements IAnnotationTransformer, IInvokedMethodListener, ITestListener, IReporter {
.....implemented methods for interface ....
}
测试类:
public class RetryProvider {
@Test (dataProvider = "datasource")
public void Test1(int code, String type, ITestContext context){
System.out.println("Test1(): " + code + " : " + type);
}
@DataProvider(name = "datasource")
public Object[][] getData(){
Object[][] data = new Object[3][2];
data[0][0] = 1;
data[0][1] = "apple";
data[1][0] = 2;
data[1][1] = "mango";
data[2][0] = 1;
data[2][1] = "guava";
return data;
}
}
测试Xml:
...<suite name="NGBug Suite">
<listeners><listener class-name="com.NGtest.RetryListener" /></listeners>
<test name="NGBug Test"><classes><class name="com.NGtest.RetryProvider" /></classes>
</test>
</suite>
测试结果:
[TestNG] [WARN] Ignoring duplicate listener : com.NGtest.RetryListener
[TestNG] [WARN] Ignoring duplicate listener : com.NGtest.RetryListener
[TestNG] [WARN] Ignoring duplicate listener : com.NGtest.RetryListener
Test1(): 1 : apple
Test1(): 2 : mango
Test1(): 3 : guava