如果很有個(gè)測(cè)試方法,并且這幾個(gè)方法又有先后順序,那么如果讓TestNG按照自己想要的方法執(zhí)行呢
一、通過(guò)Dependencies
1.在測(cè)試類中添加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,代碼中無(wú)需再添加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í)行順序,打印結(jié)果:
this is test1
this is test2
this is test3
this is test4
this is test5