testNG之组测试
@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
testNG之组测试的更多相关文章
- TestNG的组测试和组中组测试
在编写测试的过程中,我们经常遇到只想执行个别或者某一部分/某一类型的测试用例,这时我们可以使用TestNG的分组测试方法 分组测试在配置时,TestNG执行的原则是:只保留最小集合进行执行 看代码: ...
- TestNg 4.组测试中的方法分组测试
看以下代码: package com.course.testng.groups; import org.testng.annotations.AfterGroups; import org.testn ...
- testng入门教程7 TestNG组测试
在TestNG中组测试是一个新的创新功能,它不存在于JUnit框架,它允许调度到适当的部分方法和瓶坯复杂的测试方法分组.您不仅可以声明属于群体的那些方法,但你也可以指定一组包含其他组.然后,TestN ...
- 学习使用TestNG进行数据驱动测试
转自: https://mp.weixin.qq.com/s/8Bd8LEhiC2pu2VMcyNMGlQ 学习使用TestNG进行数据驱动测试 赵吃饭 51Testing软件测试网 前天 学习使 ...
- testng入门教程12 TestNG执行多线程测试
testng入门教程 TestNG执行多线程测试 testng入门教程 TestNG执行多线程测试 并行(多线程)技术在软件术语里被定义为软件.操作系统或者程序可以并行地执行另外一段程序中多个部分或者 ...
- testng多线程并行执行测试
testng多线程并行执行测试 testng多线程并行执行测试 并行(多线程)技术在软件术语里被定义为软件.操作系统或者程序可以并行地执行另外一段程序中多个部分或者子组件的能力.TestNG允许我们以 ...
- testNG之异常测试
@Test(expectedExceptions = ) 在测试的时候,某些用例的输入条件,预期结果是代码抛出异常,那么这个时候就需要testNG的异常测试,先看一段会抛出异常的代码 exceptio ...
- TestNG 组测试
方法分组测试 1. 给@Test注解后面加groups参数,如 @Test(groups = "groupa") 2. 可以添加@BeforeGroups和@AfterGroups ...
- TestNG(七)组测试
package com.course.testng.groups; import org.testng.annotations.AfterGroups; import org.testng.annot ...
随机推荐
- 每天一个Linux命令:whereis(18)
whereis whereis命令用来定位指令的二进制程序.源代码文件和man手册页等相关文件的路径. whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数- ...
- Nmon监控服务端性能
一.安装1.查看服务器操作系统的版本信息 lsb_release -a cat /etc/*release2.下载 a.nmon下载地址:http://nmon.sourceforge.net/pmw ...
- 常见Serialize技术探秘(ObjectXXStream、XML、JSON、JDBC byte编码、Protobuf)
目前业界有各种各样的网络输出传输时的序列化和反序列化方案,它们在技术上的实现的初衷和背景有较大的区别,因此在设计的架构也会有很大的区别,最终在落地后的:解析速度.对系统的影响.传输数据的大小.可维护性 ...
- 4412 搭建tftp服务器
搭建服务器 --安装xinetd,sudo apt-get install xinetd --安装tftp和tftpd,sudo apt-get install tftp tftpd --配置/etc ...
- SQL语句中,除数为0时,相应方法
在sql中做除法处理的时候,可能需要处理除数为零的情况. (1).case语句处理方法是用case when ... else 来处理 (2).nullif函数nullif函数有两个参数,定义如下:N ...
- 'Error Domain=NSURLErrorDomain Code=-999' AFNetworking请求报错
早上请求app请求登录接口发现了下面的错误信息: Error Domain=NSURLErrorDomain Code=-999 "已取消" UserInfo={NSErrorFa ...
- JSON的android应用实例
JSON的android应用实例 Json在线解析器 下面是直接通过JUnit来测试直接通过API来解析Json数据 1.普通键值对象 2.Json数组对象 3.Json数组对象
- (三)修改内核大小,适配目标板Nand flash分区配置
一. 修改内核大小 1. 在你的配置文件下uboot/include/config/xxx.h 里面有一个宏定义 #define MTDPARTS_DEFAULT "mtdparts=jz2 ...
- 2.2寸(14PIN)TFT液晶屏STM32 SPI 控制
屏幕如图所示,共14个IO口(也可能只有13个),控制屏幕的有9个IO口 详细版介绍见:http://www.ciast.net/post/20151112.html 反面IO口图: 连接通过SPI方 ...
- Python中的浮点数原理与运算分析
Python中的浮点数原理与运算分析 本文实例讲述了Python中的浮点数原理与运算.分享给大家供大家参考,具体如下: 先看一个违反直觉的例子: >>> s = 0. > ...