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 = 1priority = 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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/419923.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

html按钮不可选中,如何使HTML文本不可选择

小编典典用普通的HTML无法做到这一点&#xff0c;因此JSF在这里也无法为您做很多事情。如果您仅针对体面的浏览器&#xff0c;则只需使用CSS3&#xff1a;.unselectable {-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: n…

小米手机扩容教程_小米笔记本硬盘扩容教程:5分钟搞定,存储容量瞬间翻倍...

想要了解更多热门资讯、玩机技巧、数码评测、科普深扒&#xff0c;可以点击右上角关注我们的百家号&#xff1a;雷科技----------------------------------现在&#xff0c;固态硬盘在笔记本上基本上已经普及了&#xff0c;相比机械硬盘&#xff0c;它的优势很明显&#xff0c;…

[转]你所不知道的超级瘦腿运动——空中蹬自行车

转自&#xff1a;http://weibo.com/p/1001603808616690912493?frompage_100505_profile&wvr6&modwenzhangmod 看似平淡无奇&#xff0c;实则大有文章。普通的蹬法1000个也没用&#xff0c;海龟版本的蹬法每天30个就可以修炼出绝世美腿、平坦小腹、并且有效改善X、O型腿…

计算机快捷键知识点,电脑常用快捷键基础的知识点(12页)-原创力文档

电脑常用快捷键基础知识按” shift ”&#xff0b;”6” 是省略号……&#xff0c;方法&#xff1a; shift6 (主键盘上的 6&#xff0c;就是 Y 键对上去的那个 6), 前提是在你有五笔输入法的状态栏上 , 必须是中文标点 , 就是有个软件盘的旁边那个标点符号必须是空心的 .)另一个…

pandas用均值填充nan_python – 如何用pandas中的滚动平均值填充nan值

这应该工作&#xff1a;input_data_frame[var_list] input_data_frame[var_list].fillna(pd.rolling_mean(input_data_frame[var_list], 6, min_periods1))请注意,窗口为6,因为它包含NaN本身的值(不计入平均值).此外,其他NaN值不用于平均值,因此如果在窗口中找到的值少于5个,则…

Java 默认/缺省 内存大小,如果没有 -Xms -Xmx

命令 java -XX:PrintCommandLineFlags -version 会直观的输出下面默认值 -XX:InitialHeapSize16336768 -XX:MaxHeapSize522776576 -XX:PrintCommandLineFlags 转载于:https://www.cnblogs.com/tang88seng/p/4498866.html

html菜鸟ruby,Ruby 循环

Ruby 循环Ruby 中的循环用于执行相同的代码块若干次。本章节将详细介绍 Ruby 支持的所有循环语句。Ruby while 语句语法whileconditional[do]codeend或者语法whileconditional[:]codeend当 conditional 为真时&#xff0c;执行 code。语法中 do 或 : 可以省略不写。但若要在一行…

jenkins是什么_使用 Jenkins 自动发布服务到 Kubernetes

使用 Jenkins 自动发布服务到 KubernetesJenkins 是什么一个比较流行的开源 CI/CD 工具CI/CD : 持续集成/持续部署Kubernetes 是什么容器化工具 -- 一个开源的&#xff0c;用于管理云平台中多个主机上的容器化的应用&#xff0c;Kubernetes的目标是让部署容器化的应用简单并且高…

2015.5.12站立会议

昨天我们将查阅的资料汇总&#xff0c;并进行了了解和分析&#xff0c;每个人都发表了自己在查阅资料过程中的认识和对这部分的理解&#xff0c;大家交换了意见。 今天我们准备将所了解的内容代码化&#xff0c;每人编写一部分代码&#xff0c;利用所查找的资料。 遇到的问题&a…

grav html5,如何通过html5实现摇一摇的功能

原理&#xff1a;使用DeviceMotion实现&#xff0c;关于DeviceMotion介绍可以查看https://developer.mozilla.org/en-US/docs/Web/Reference/Events/devicemotion通过DeviceMotionEvent&#xff0c;可以获得accelerationIncludingGravity的x,y,z属性&#xff0c;根据x,y,z属性的…

WPF DataGrid

前台代码 <DataGrid Name"gv_GetWork" AutoGenerateColumns"False" CanUserSortColumns"False" CanUserAddRows"False" Margin"5"> <!--鼠标经过事件--> <DataGrid.RowStyle> <Style TargetType"…

小程序怎么打出横线效果_成都小程序开发:哪些因素会影响小程序的运营效果?...

相信现在微信小程序对于大家来说都不陌生了&#xff0c;目前小程序在市场中的占有率比较高&#xff0c;也是用户比较喜欢的平台。对于初次开发小程序的企业商家&#xff0c;在小程序的开发运营时&#xff0c;往往会有一些细节性的问题&#xff0c;影响到小程序的运营效果。我们…

Android监听ScrollView滑动到顶端和底部

Android监听ScrollView滑动到顶端和底部package cn.testscrollview;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.ScrollView;import android.app.Activity;/*** Demo…

前端学习(1484):json-server工具使用

创建文件 json.db {"brands": [{"name": "TCL","date": "2018-05-30T08:07:20.0892","id": 1},{ "name": "TCL", "date": "2018-05-30T08:07:20.0892", "id"…

快照速度_网络推广——网络推广专员如何看待网站快照更新快慢问题?

百度搜索引擎针对网站快照更新的问题曾有言明&#xff0c;表示网站快照的更新快慢与网站权重没有太多的直接关系&#xff0c;因为搜索引擎对网站抓取频率与快照更新是两个不同的概念&#xff0c;然而有很多站长表示快照更新慢是不是因为网站内部出现问题&#xff1f;或者是网站…

浙江大学计算机学院工业设计复试比,2021浙江大学计算机学院工业设计工程研究生入学考试范围调整啦...

关于发布工业设计工程研究生入学考试范围的通知本通知为预通知&#xff0c;如有调整&#xff0c;以浙江大学研究生院正式发布的2021年硕士研究生招生简章及招生目录为准。自2021年硕士研究生招生考试(2020年冬季)起&#xff0c;浙江大学工业设计工程(计算机学院、软件学院)考试…

qtp的三种录制模式(转)

QTP提供三种不同的录制方式&#xff1a;正常录制&#xff08;Normal Recording&#xff09;、模拟录制&#xff08;Analog Recording&#xff09;和低级录制&#xff08;Low Level Recording&#xff09;。 1.正常录制&#xff08;Normal Recording&#xff09;  QTP默认的录…

kafka python框架_为什么选择R而不是Python做ETL

导读&#xff1a;1. 打破R慢的印象&#xff0c;ETL效率显著优于Python&#xff0c;堪比spark&#xff0c;clickhouse2. 对比python中的datatable、pandas、dask、cuDF、modin&#xff0c;R中data.table以及spark、clickhouse3. 探讨R中的ETL体系ETL在数据工作中起着至关重要的作…