Is it possible to get the value of parameters that are used to initialize a @Factory annotated test class from any of the ITestListener, ISuiteListener or any other listener methods?
Below is a sample test class. My intention is to get the value of the class init parameter 'value' using any of the listener methods, possibly.
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();
}
}
Thanks in advance.