工厂数据提供者测试结果。
package kill.me.later;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
public class SomeTest {
private int id = 0;
private String account = "";
public SomeTest(int id, String account) {
this.id = id;
this.account = account;
}
//test
@Test
public void firstTest() {
System.out.println("Test #1 with data: "+id+". "+account);
assertTrue(true);
}
@Test
public void secondTest() {
System.out.println("Test #2 with data: "+id+". "+account);
assertTrue(true);
}
@Test
public void thirdTest() {
System.out.println("Test #3 with data: "+id+". "+account);
assertTrue(true);
}
}
工厂类
package kill.me.later;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
public class SampleFactory {
@Factory(dataProvider="dp")
public Object[] createInstances(int id, String account) {
return new Object[] {new SomeTest(id, account)};
}
@DataProvider(name="dp")
public static Object[][] dataProvider() {
Object[][] dataArray = {
{1, "user1"},
{2, "user2"}
};
return dataArray;
}
}
当我在套房下面跑时,我得到如下结果
LocalSuite ParticularTest SomeTest firstTest secondTest thirdTest firstTest(1) secondTest(2) thirdTest(3)
但是我希望每个数据集分开的结果与具有3个测试的同一个类运行。如下所示
LocalSuite ParticularTest TestScenario1 firstTest secondTest thirdTest TestScenario2 firstTest(1) secondTest(2) thirdTest(3)
<suite name="LocalSuite" verbose="1">
<test name="ParticularTest" group-by-instances="true">
<classes>
<class name="kill.me.later.SampleFactory"></class>
</classes>
</test>
</suite>