(八)TestNG 用例依赖

当某一条用例运行失败时,其它用例必然也会失败,所以,我们就没有必要再运行其它用例了,这个时候我们就可以设置用例之间的依赖。

测试方法依赖


import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;


public class DependentMethodsTest { @Test publicvoidtestAdd1(){ assertEquals(3+1, 5); } @Test(dependsOnMethods = {"testAdd1"}) publicvoidtestAdd2(){ assertEquals(3+2, 5); } } 
  • dependsOnMethods 来设置用例的依赖,当 testAdd1() 运行失败时,则 testAdd2() 不再被执行。

测试组依赖


import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;


public class DependentGroupsTest { @Test(groups={"funtest"}) publicvoidtestAdd1(){ assertEquals(3+1, 5); } @Test(groups={"funtest"}) publicvoidtestAdd2(){ assertEquals(3+2, 5); } @Test(dependsOnGroups = {"funtest"}) publicvoidtestAdd3(){ assertEquals(3+2, 5); } } 
  • dependsOnGroups 来设置组的依赖,testAdd1()和 testAdd2() 同属于于 funtest组,testAdd3() 依赖于funtest组,该组有中有一条用例运行失败,则testAdd3() 不再执行。

猜你喜欢

转载自www.cnblogs.com/xinlan06/p/11498772.html