@Test(groups = {""})

  在执行测试用例的时候,往往一个功能依赖多个测试用例,比如流程的测试,那么这个时候就可以用到组测试,把流程涉及到测试用例都分到同一组里,按组执行即可。

  testNG的组通过@Test的groups属性来指定的,一个方法可以属于一个组(@Test(groups = {"checkintest"})),也可以属于多个组(@Test(groups = {"functest","checkintest"}))。

  假设现在有3个java代码,common.java、functionA.java、functionB.java,测试流程涉及到common.java中 login() 和 quit() 方法、functionA.java中的 testMethod1() 方法、functionB.java中的 testMethod3() 方法,那么可以将这4个方法分到同一组里functest,代码如下:

common.java:

import org.testng.annotations.Test;public class common {@Test(groups = {"functest","checkintest"})public void login() {System.out.println("login");}@Test(groups = {"functest","checkintest"})public void quit() {System.out.println("quit");}@Test(groups = {"checkintest"})public void init() {System.out.println("init");}
}

functionA.java:

import org.testng.annotations.Test;public class functionA {@Test(groups = {"functest"})public void testMethod1() {System.out.println("this is testMethod1");        } @Test(groups = {"functest2"})public void testMethod2() {System.out.println("this is testMethod2");        }
}

functionB.java:

import org.testng.annotations.Test;public class functionB {@Test(groups = {"functest"})public void testMethod3() {System.out.println("this is testMethod3");        } @Test(groups = {"functest2"})public void testMethod4() {System.out.println("this is testMethod4");        }
}

testng.xml:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" ><suite name="Suite1" verbose="1" ><test name="Regression1" preserve-order="true"><groups><run><include name = "functest" /></run>        </groups><classes><class name="common"></class><class name="functionA"></class><class name="functionB"></class></classes></test>
</suite>

注意:testng.xml需要指定要测试的组(<groups>……</groups>)和组所在的class(<classes>……</classes>)

运行testng.xml,执行结果如下:

login
quit
this is testMethod1
this is testMethod3

@Test(priority = )

一般quit都是在流程的最后才执行,如何控制组里方法执行的顺序呢?可以通过@Test的priority属性,testNG按照priority从小到大的顺序执行

修改common.java,在@Test中添加属性priority = 1和priority = 4:

import org.testng.annotations.Test;public class common {@Test(groups = {"functest","checkintest"},priority = 1)public void login() {System.out.println("login");}@Test(groups = {"functest","checkintest"},priority = 4)public void quit() {System.out.println("quit");}@Test(groups = {"checkintest"})public void init() {System.out.println("init");}
}

修改functionA.java,在@Test中添加属性priority = 2:

import org.testng.annotations.Test;public class functionA {@Test(groups = {"functest"},priority = 2)public void testMethod1() {System.out.println("this is testMethod1");        } @Test(groups = {"functest2"})public void testMethod2() {System.out.println("this is testMethod2");        }
}

修改functionB.java,在@Test中添加属性priority = 3:

import org.testng.annotations.Test;public class functionB {@Test(groups = {"functest"}, priority = 3)public void testMethod3() {System.out.println("this is testMethod3");        } @Test(groups = {"functest2"})public void testMethod4() {System.out.println("this is testMethod4");        }
}

再次运行testng.xml,执行结果如下:

login
this is testMethod1
this is testMethod3
quit

如何只执行组里 testMethod1() 和 testMethod3() 方法,而不执行 login() 和 quit() 方法呢?

修改testng.xml,添加<exclude name="checkintest"></exclude>,排除在checkintest组里的方法

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" ><suite name="Suite1" verbose="1" ><test name="Regression1" preserve-order="true"><groups><run><include name = "functest" /><exclude name="checkintest"></exclude></run>        </groups><classes><class name="common"></class><class name="functionA"></class><class name="functionB"></class></classes></test>
</suite>

再次运行testng.xml,执行结果如下:

this is testMethod1
this is testMethod3

转载于:https://www.cnblogs.com/yuan-yuan/p/4498134.html

testNG之组测试相关推荐

  1. Fortinet“安立方”架构获得NSS Labs BDS 组测试多攻击维度100%检出率佳绩

    Fortinet(NASDAQ:FTNT),近日公布了在NSS Labs最新违规检测系统(BDS:Breach Detection System) 组测试 中的成绩.Fortinet参加测试的沙箱解决 ...

  2. 使用TestNG的弹簧测试支持

    TestNG是一个测试框架,旨在涵盖所有类别的测试:单元,功能,端到端,集成等. 它包括许多功能,例如灵活的测试配置,对数据驱动测试的支持(使用@DataProvider),强大的执行模型(不再需要T ...

  3. (保守群组测试 非保守群组测试 二次重复测试 自适应二次重复测试)四种群体测试的C++代码

    目录 原理 保守组检测 非保守组检测 二次重复测试 自适应二次重复测试 四种测试方法的核心代码 保守群组测试 非保守群组测试 二次重复测试与自适应二次重复测试 测试代码 参考文献 原理 假设该病在人群 ...

  4. 链接:https://ac.nowcoder.com/acm/problem/22228来源:牛客网题目描述 在给定的数组中删除一个数。输入描述:多组测试。每组第一行输入1个整数n(n

    链接:登录-专业IT笔试面试备考平台_牛客网 来源:牛客网 题目描述 在给定的数组中删除一个数. 输入描述: 多组测试. 每组第一行输入1个整数n(n<20), 第二行输入n个整数 第三行输入1 ...

  5. Fortinet安立方架构获得NSS Labs BDS 组测试多攻击维度100%检出率佳绩

    Fortinet公司产品和解决方案高级副总裁John Maddison "网络罪犯正以惊人的速度不断开发新的攻击策略,从数据泄露到完全入侵仅需几分钟的情况也不是不可能.这使得快速检测和自动响 ...

  6. 群组测试(Group testing)介绍

    最近了解了群组测试 (Group testing) 的一些内容,在这里做个记录与分享. 问题引入 问题源于二战时期,美国需要通过血样检测美军是否携带梅毒,但是当时血液检测耗时耗钱,将每个士兵的血液都检 ...

  7. USACO铜组测试3

    USACO铜组测试3 T1-奶牛年轮 Dir42. 奶牛年轮 时间限制:1.0s 内存限制:256.0MB 输入文件名:yearcow.in 输出文件名:yearcow.out 试题来源:USACO ...

  8. java持续集成soapui_集成testNG到JavaAPI测试-执行多条用例

    ***************************************************************** 在这门课里你将学到Web Services(SOAP WebServ ...

  9. 电池pack结构_3C锂电池pack中,使用弹片微针模组测试基本性能和大电流

    3C锂电池有着循环寿命长.低温度放电性能好.续航能力强.比能量高.荷电保持能力强的优点,在3c消费电子领域方面应用范围广泛.由于3c锂电池的广泛应用,需求量极大,很多厂家开始自己掌握3C锂电池pack ...

最新文章

  1. sql语言管理中计算机系统,00051管理系统中计算机应用第四章数据库系统考纲
  2. 我的Ubuntu9.10配置(随时更新)
  3. 浅析C#中构建多线程应用程序
  4. 虚存的用法计算机组成原理,5.5虚拟存储器计算机组成原理.pdf
  5. Kinect v1和Kinect v2的彻底比较
  6. 程序员有成立工会的理由吗?
  7. python模块导入与使用
  8. csdn积分获取攻略
  9. Qt Console Application
  10. 前端开发之谷歌实用插件fehelper JSON助手
  11. 合并两个有序链表js
  12. 国家测绘局干部双向挂职锻炼管理暂行办法
  13. java 反射基础_Java反射的基本使
  14. bitblt和getpixel哪个更效率
  15. 计算机各种硬盘的规格,PS4硬盘基本规格和普通电脑硬盘有何区别?具体解析一览...
  16. 畜牧兽医专业跨考计算机,可以跨专业报考兽医吗
  17. 计算机电路板 接地,pcb电路板接地怎么接
  18. 计算机毕业设计(9)python毕设作品之校园失物招领系统
  19. Eight HDU - 1043
  20. android tmp目录权限不够,android - 使用root用户安装APK,处理“ / data / local / tmp /”文件夹的新限制 - 堆栈内存溢出...

热门文章

  1. Bash字符串处理(与Java对照) - 19.查找字符的位置
  2. vue-cli3项目通过vue如何引入第三方js包完成登陆功能
  3. 重学java基础第二十课:环境配置和第一个helloWorld
  4. react学习(6)----react样式多用内联
  5. 前端学习(2890):如何短时间内实现v-for 模板编译321
  6. [css] Reset CSS和Normalize CSS的区别是什么?
  7. [css] 如何给文字的color设置渐变
  8. [js] 根据元素ID遍历树形结构,查找到所有父元素ID
  9. 前端学习(2825):vs开发小程序的插件
  10. 前端学习(2753):创建新页面和页面配置