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

  testNG傳參數(shù)的兩種方式(xml文件,@DataProvider)
  使用testng.xml設(shè)置參數(shù)
  參數(shù)在xml文件中可以在suite級(jí)別定義,也可以在test級(jí)別定義;testNG會(huì)嘗試先在包含當(dāng)前類的test標(biāo)簽中尋找參數(shù),如果沒(méi)找到則在上層的suite標(biāo)簽中查找。即在test標(biāo)簽中相同的參數(shù)對(duì)當(dāng)前類當(dāng)前方法的優(yōu)先級(jí)比較高。 testNG支持這種傳參方式的類型如下:String、 int/Integer、boolean/Boolean、 byte/Byte、 char/Character、
double/Double、 float/Float、 long/Long、 short/Short。對(duì)于非上述類型TestNG無(wú)法通過(guò)這種方式進(jìn)行傳參,可以通過(guò)@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);
}
}

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