【发布时间】:2016-06-29 19:56:33
【问题描述】:
是否可以从任何 ITestListener、ISuiteListener 或任何其他侦听器方法中获取用于初始化 @Factory 注释测试类的参数值?
下面是一个示例测试类。我的意图是使用任何侦听器方法获取类初始化参数“值”的值,可能。
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.reporters.EmailableReporter2;
@Listeners({ TestExecutionListener.class, EmailableReporter2.class })
public class TestClass {
private int value;
@Factory(dataProvider = "data", dataProviderClass = TestClass.class)
public TestClass(final int value) {
this.value = value;
}
@Test(alwaysRun = true)
public void testOdd() {
Assert.assertTrue(value % 2 != 0);
}
@Test(alwaysRun = true)
public void testEven() {
Assert.assertTrue(value % 2 == 0);
}
@DataProvider(name = "data")
public static Iterator<Object[]> data() {
List<Object[]> list = new ArrayList<>();
for (int i = 0; i < 2; i++) {
list.add(new Object[] { i });
}
return list.iterator();
}
}
提前致谢。
【问题讨论】:
标签: java testng listener factory testng-dataprovider