所以我擔心的是,所有的測試應與第一個參數空氣首先運行,然後再所有測試應與下一個參數「土」執行
這裏是我得到的輸出輸入 「空氣」 和 「大地」
Test-1 with data: Air
Test-2 with data: Air
Test-1 with data: Water
Test-2 with data: Water
測試類 - RandomTest
public class RandomTest {
private String str = "";
public RandomTest(String str) {
this.str = str;
}
@Test
public void firstTest() {
System.out.println("Test-1 with data: "+str);
}
@Test
public void secondTest() {
System.out.println("Test-2 with data: "+str);
}}
工廠類 - SampleFactory
public class SampleFactory {
@Factory(dataProvider="dp")
public Object[] createInstances(String str) {
return new Object[] {new RandomTest(str)};
}
@DataProvider(name="dp")
public static Object[][] createData() {
return new Object[][] {
new Object[] { new String("Air") },
new Object[] { new String("Water") }
};
}}
運行從的testng.xml類SampleFactory, 請注意:組按實例= 「真」
<suite name="Suite-A" verbose="1">
<test name="test" group-by-instances="true">
<classes>
<class name="tests.SampleFactory"></class>
</classes>
</test>
</suite>
編號:http://testng.org/doc/documentation-main.html#factories
參考文獻:http://java.dzone.com/articles/testng-run-tests-sequentially
感謝那些真正幫助望着窗外的確切的事情:) – 2014-08-31 14:45:39