您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > TestNG
TestNG參數(shù)傳遞方式
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2015/7/24 10:08:46 ] 推薦標(biāo)簽:單元測試工具

  testNG傳參數(shù)的兩種方式(xml文件,@DataProvider)
  使用testng.xml設(shè)置參數(shù)
  參數(shù)在xml文件中可以在suite級別定義,也可以在test級別定義;testNG會嘗試先在包含當(dāng)前類的test標(biāo)簽中尋找參數(shù),如果沒找到則在上層的suite標(biāo)簽中查找。即在test標(biāo)簽中相同的參數(shù)對當(dāng)前類當(dāng)前方法的優(yōu)先級比較高。 testNG支持這種傳參方式的類型如下:String、 int/Integer、boolean/Boolean、 byte/Byte、 char/Character、
double/Double、 float/Float、 long/Long、 short/Short。對于非上述類型TestNG無法通過這種方式進行傳參,可以通過@DataProvider方式傳參
public class ParameterTest {
/**
* Following method takes one parameter as input. Value of the
* said parameter is defined at suite level.
*/
@Parameters({ "suite-param" })
@Test
public void prameterTestOne(String param) {
System.out.println("Test one suite param is: " + param);
}
/**
* Following method takes one parameter as input. Value of the
* said parameter is defined at test level.
*/
@Parameters({ "test-two-param" })
@Test
public void prameterTestTwo(String param) {
System.out.println("Test two param is: " + param);
}
/**
* Following method takes two parameters as input. Value of the
* test parameter is defined at test level. The suite level
* parameter is overridden at the test level.
*/
@Parameters({ "suite-param", "test-three-param" })
@Test
public void prameterTestThree(String param, String paramTwo) {
System.out.println("Test three suite param is: " + param);
System.out.println("Test three param is: " + paramTwo);
}
}

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd