目录如下:

TestGroup.java 代码如下:

package com.testng.cn;

import org.testng.annotations.*;

import static org.testng.Assert.assertEquals;

public class TestGroup {

    @Test(groups={"高", "正常"})
public void testCase1(){
assertEquals(1+1, 2);
} @Test(groups = {"高", "正常"})
public void testCase2(){
assertEquals(5-1, 4);
} @Test(groups = {"中", "正常"})
public void testCase3(){
assertEquals(2/2, 1);
} @Test(groups = {"低", "异常"})
public void testCase4(){
assertEquals(1/0, 1);
}
}

上面代码我们按照两种程度划分

  • 重要程度: 低——>中——>高
  • 类型: 正常——>异常

testng.xml  文件配置,我们运行正常的测试用例,但是排除等级高的测试用例,所以就是运行testCase3这条测试用例

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="测试套件" verbose="1" >
<test name="简单测试">
<groups>
<run>
<exclude name="高" /> <!-- 排除不执行的测试用例 -->
<include name="正常" /> <!-- 指定执行的测试用例 -->
</run>
</groups>
<classes>
<class name="com.testng.cn.TestGroup"/>
</classes>
</test>
</suite>
  • <groups>...</groups> 测试组标签。

  • <run>...</run> 运行测试。

  • <exclude> 根据 groups 的设置, 排除不执行的用例。
  • <include> 根据 groups 的设置, 指定执行的测试用例。

运行结果:

13、testng.xml对用例进行分组的更多相关文章

  1. 14、testng.xml 设置用例执行顺序

    目录如下: TestGroup.java 代码如下: package com.testng.cn; import org.testng.annotations.*; import static org ...

  2. testng.xml 配置大全

    1.TestNG的运行方式如下: 1 With a testng.xml file 直接run as test suite 2 With ant 使用ant 3 From the command li ...

  3. testng跑失败用例重试

    testng 提高用例通过率,失败用例要重新运行一次 步骤: 1.新建一个Retry 类,implements IRetryAnalyzer接口,这个类里面确定重跑次数,以及分析每次失败是否需要重新运 ...

  4. 创建testng.xml文件

    简单介绍 运行TestNG测试脚本有两种方式:一种是直接通过IDE运行(例如使用eclipse中的“Run TestNG tests”),另一种是从命令行运行(通过使用xml配置文件).当我们想执行某 ...

  5. Java - Test - TestNG: testng.xml 元素 group

    1. 概述 group 相关的元素 groups run 其他相关(不准备提了) package class include exclude 2. 背景 准备 了解了 class 及其子元素 问题 对 ...

  6. Java - Test - TestNG: testng.xml 元素 package

    1. 概述 简介 package 元素 packages package exclude include 2. 背景 准备 自动生成了 testng.xml 文件 已经基本了解了 testng.xml ...

  7. testng.xml文件结构组成及节点属性说明

    TestNG的DTD检查文件:http://testng.org/testng-1.0.dtd.PHP 更多testng配置及说明,请移步http://testdoc.org/docmaster?pi ...

  8. testng xml 示例

    TestNG的DTD检查文件:http://testng.org/testng-1.0.dtd.php 更多testng配置及说明,请移步http://testdoc.org/docmaster?pi ...

  9. IDEA 单元测试testng入门及testng.xml

    直接进入正题: 1.TestNG的运行方式如下: With a testng.xml file 直接run as test suite With ant 使用ant From the command ...

随机推荐

  1. PAT 1042 Shuffling Machine (20 分)

    1042 Shuffling Machine (20 分)   Shuffling is a procedure used to randomize a deck of playing cards. ...

  2. Eclipse Missing artifact jdk.tools:jdk.tools:jar:1.6

    Missing artifact jdk.tools:jdk.tools:jar:1.6 问题出在Eclipse Maven的支持上,在Eclipse下,java.home变量设置为用于启动Eclip ...

  3. JSP 虚拟路径设置

    编辑server.xml 在Host标签内加  :path为虚拟路径  docBase为绝对路径 <Context path="/icon"  docBase="C ...

  4. Python List列表的操作说明

    Python中List的N种操作,其简单程度令人叹为观止... C:\Users\rhys>python Python 2.7.14 (v2.7.14:84471935ed, Sep 16 20 ...

  5. SpringBoot集成Thymeleaf模板

    1.添加起步依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId& ...

  6. 天天用Synchronized,底层原理是个啥?

    作者:liuxiaopeng https://www.cnblogs.com/paddix/p/5367116.html Synchronized 的基本使用 Synchronized 的作用主要有三 ...

  7. application/json和application/x-www-form-urlencoded参数接收

    application/json ajax请求中content-type:application/json代表参数以json字符串传递给后台,controller接收需要@RequestBody 接收 ...

  8. PyCharm与git/GitHub取消关联

    如果你从github 上down下的个项目,用pycharm 打开的时候,选择了git管理,导致你只要做了修改,就会有颜失标记,即使没有强迫症,看着也很难受啊 聪敏的我赶快找度娘,总结如下解决方法 在 ...

  9. 自定义DbUtils通用类

    本实例使用C3P0连接池做连接,详见https://www.cnblogs.com/qf123/p/10097662.html开源连接池C3P0的使用 DBUtils.java package com ...

  10. tex, virtex, initex - 文本格式化和排版

    SYNOPSIS 总览 tex [options] [commands] DESCRIPTION 描述 这份手册页并不全面.此版本的 TeX 完整的文档可以从 info 文件或者手册 Web2C: A ...