Trying to learn how to use @Factory, but when I execute it in one of two ways, i get either an error or no tests get executed at all. I am invoking the XML file in Eclipse, by right-clicking on it, and selecting "Run As TestNG Suite".
With this XML file, the suite executes, but zero tests are picked up/executed:
<suite name="suite1" verbose="5">
<test name="test1">
<classes>
<class name="qa.tests.MyFactory"/>
</classes>
</test>
</suite>
With this XML file, i get a test failure with an exception:
<suite name="suite1" verbose="5">
<test name="test1">
<packages>
<package name="qa.tests" />
</packages>
</test>
</suite>
Error:
Can't invoke public void qa.tests.MyTest.testSample1(): either make it static or add a no-args constructor to your class
MyFactory.java class:
package qa.tests;
import org.testng.annotations.Factory;
public class MyFactory {
@Factory
public Object[][] dp() {
Object[][] data = new Object[][] {
{ "1", "TestCase1", "Sample test 1" },
{ "2", "TestCase2", "Sample test 2" },
{ "3", "TestCase3", "Sample test 3" }
};
return data;
}
}
MyTest.java class:
package qa.tests;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class MyTest {
private String num;
private String name;
private String desc;
public MyTest(String num, String name, String desc) {
this.num = num;
this.name = name;
this.desc = desc;
}
@Test()
public void testSample1() {
System.out.println(num + ", " + name + ", " + desc);
assertTrue( true );
}
}
What in the world am I doing incorrectly?