您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > TestNG
TestNG之執(zhí)行順序
作者:網(wǎng)絡轉載 發(fā)布時間:[ 2016/1/5 11:21:48 ] 推薦標簽:軟件測試工具 單元測試工具

  如果很有個測試方法,并且這幾個方法又有先后順序,那么如果讓TestNG按照自己想要的方法執(zhí)行呢
  一、通過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");
}
  執(zhí)行順序,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>
  執(zhí)行順序,打印結果:
  this is test1
  this is test2
  this is test3
  this is test4
  this is test5

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