TestNG参数传递方式

发表于:2015-7-23 13:23

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:silenceer    来源:51Testing软件测试网采编

  testNG传参数的两种方式(xml文件,@DataProvider)
  使用testng.xml设置参数
  参数在xml文件中可以在suite级别定义,也可以在test级别定义;testNG会尝试先在包含当前类的test标签中寻找参数,如果没找到则在上层的suite标签中查找。即在test标签中相同的参数对当前类当前方法的优先级比较高。 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);
}
}
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号