dependsOnMethods与dependsOnGroups 属性主要用来处理测试用例之间测依赖关系 dependsOnMethods主要是方法之间的依赖
具体如下:
@Test(description="登录测试" )
public void Testlogin() {
logger.info("测试登录失败");
Assert.fail();
}
@Test(description="依赖登录" ,dependsOnMethods= {"Testlogin"})
public void TestPayOrder() {
System.out.println("----支付购买----");
logger.info("登陆成功---可以支付购买物品");
}
依赖测试,如果依项测试失败则该测试用例也不执行
如果依赖的用例不是在同一个方法里面需要这样处理:加上包名.类名.方法名
@Test(description="依赖登录" ,dependsOnMethods= {"TestNg.TestTieOut.testenable"})
dependsOnGroups 依赖是分组之间
@Test(description="测试分组" ,groups= {"operation"})
public void TestGroupAdd() {
System.out.print(String.valueOf(11+12));
}
@Test(description="测试分组" ,groups= {"operation","Animal"})
public void TestGroupAnimal() {
System.out.printf("animal 动物");
}
@Test(description="测试分组" ,dependsOnGroups= {"Animal"})
public void TestGroupCat() {
System.out.printf("cat 喵喵");
}
testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
<test verbose="2" preserve-order="true" name="D:/IdeaProject/interfaceRestAssured">
<groups>
<define name="groups" >
<include name="operation"></include>
<include name="Animal"></include>
</define>
<run>
<include name="groups"></include>
<!-- <exclude name="operation"></exclude>-->
</run>
</groups>
<classes>
<class name="TestNg.TestGroup"></class>
</classes>
</test>
<!-- <listeners>
<listener class-name="report.ExtentReport"></listener>
</listeners>-->
<!-- 这是reportNG的监听类-->
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"></listener>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"></listener>
</listeners>
</suite>
测试testng.xml