TestNG之执行顺序

发表于:2016-1-04 12:01

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

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

  如果很有个测试方法,并且这几个方法又有先后顺序,那么如果让TestNG按照自己想要的方法执行呢
  一、通过Dependencies
  1.在测试类中添加Dependencies
@Test
public void test1() {
System.out.println("this is test1");
}
@Test(dependsOnMethods = { "test1" })
public void test2() {
System.out.println("this is test2");
}
@Test(dependsOnMethods = { "test2" })
public void test3() {
System.out.println("this is test3");
}
@Test(dependsOnMethods = { "test3" })
public void test4() {
System.out.println("this is test4");
}
@Test(dependsOnMethods = { "test4" })
public void test5() {
System.out.println("this is test5");
}
  执行顺序,print:
  this is test1
  this is test2
  this is test3
  this is test4
  this is test5
  2.在xml文件中添加Dependencies,代码中无需再添加Dependencies
<test name="Test">
<classes>
<class name="test.testng.TestOrder"/>
<methods>
<dependencies>
<method name="test2" depends-on="test1"/>
<method name="test3" depends-on="test2"/>
<method name="test4" depends-on="test3"/>
<method name="test5" depends-on="test4"/>
<method name="test1" />
</dependencies>
</methods>
</classes>
</test>
  执行顺序,打印结果:
  this is test1
  this is test2
  this is test3
  this is test4
  this is test5
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号