TESTNG组测试

在编写测试的过程中,我们经常遇到只想执行个别或者某一部分/某一类型的测试用例,这时我们可以使用TestNG的分组测试方法。

代码:

public class GroupTestExample {
@Test(groups={"group1","group2"})
public void f1(){
System.out.println("f1() grou is group1 and group2");
}
@Test(groups={"group1"})
public void f2(){
System.out.println("f2() grou is group1");
}
@Test(groups={"group2"})
public void f3(){
System.out.println("f3() grou is  group2");
}
@Test(groups={"group1","group2"})
public void f4(){
System.out.println("f4() grou is group1 and group2");
}
}

testng.xml文件配置

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
  <test name="Test">
    <groups>
        <run>
            <include name="group2"/>
        </run>
    </groups>
    <classes>
      <class name="com.testcase.GroupTestExample"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

运行结果:

[TestNG] Running:
  F:\android\android_work\Test2\src\testng.xml


f1() grou is group1 and group2
f3() grou is  group2
f4() grou is group1 and group2


===============================================
Suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================


组中组

代码:

public class TestngGroupsOfGroups {  
  
    @Test(groups = { "windows.xp" })  
    public void testMethod5() {  
        System.err.println("(groups = { windows.xp })");  
    }  
  
    @Test(groups = { "windows.7" })  
    public void testMethod6() {  
        System.err.println("(groups = { windows.7 })");  
    }  
  
    @Test(groups = { "windows.8" })  
    public void testMethod7() {  
        System.err.println("(groups = { windows.8 })");  
    }  
}  

testng.xml配置

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">  
  3. <suite name="framework_testng">  
  4.     <test verbose="2" name="TestGroupsOfGroups">  
  5.         <groups>  
  6.             <define name="windows.xp">  
  7.                 <include name="windows.xp" />  
  8.             </define>  
  9.             <define name="windows.7">  
  10.                 <include name="windows.7" />  
  11.             </define>  
  12.             <define name="all">  
  13.                 <include name="windows.*" />  
  14.             </define>  
  15.             <run>  
  16.                 <include name="all" />  
  17.                 <exclude name="windows.7" />  
  18.             </run>  
  19.         </groups>  
  20.         <classes>  
  21.             <class name="com.dragon.testng.annotation.TestngGroupsOfGroups" />  
  22.         </classes>  
  23.     </test>  
  24. </suite>  
执行结果:

  1. (groups = { windows.xp })  
  2. (groups = { windows.8 })  
  3. PASSED: testMethod5  
  4. PASSED: testMethod7  
  5.   
  6. ===============================================  
  7.     TestGroupsOfGroups  
  8.     Tests run: 2, Failures: 0, Skips: 0  
  9. ===============================================  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值