隨着TestNG,你可以使用組此:
@BeforeMethod(groups = "g1")
public void setUp1(){
obj.addDataThisWay(data);
}
@BeforeMethod(groups = "g2")
public void setUp2(){
obj.addDataThatWay(data);
}
@Test(groups = { "g1", "g2" })
public void testResult(){
assertEquals(obj.getResult(),1);
}
如果你問TestNG的運行組 「G1」,它將運行設置1() - > TestResult中。如果你運行組「g2」,它將運行setUp2() - > testResult。
此外,像上面說的評論者,可以使用數據提供不同的參數傳遞給您的測試方法:
//This method will provide data to any test method that declares that its Data Provider
//is named "test1"
@DataProvider(name = "test1")
public Object[][] createData1() {
return new Object[][] {
{ "Cedric", new Integer(36) },
{ "Anne", new Integer(37)},
};
}
//This test method declares that its data should be supplied by the Data Provider
//named "test1"
@Test(dataProvider = "test1")
public void verifyData1(String n1, Integer n2) {
System.out.println(n1 + " " + n2);
}
TestNG中您可以使用@dataProvider註釋,並設置這樣做的方式,傳遞obj的兩個不同的實例。但我不知道junit等值是什麼。 – sblundy