zoukankan      html  css  js  c++  java
  • TestNg 5.类分组

    类分组是可以给类去分组,几个类分成不同的组。

    比如,建立3个类GroupsOnClass1,GroupsOnClass2,GroupsOnClass3.   GroupsOnClass1和GroupsOnClass2是一类(stu),GroupsOnClass3是一类(teacher)。

    在resource里面在新建一个groupsOnClass.xml

    以下是目录结构:

    代码如下:@Test可以加到类外面,和家在每个方法前面是一样的效果。

    #GroupsOnClass1
    
    package com.course.testng.groups;
    
    import org.testng.annotations.Test;
    
    @Test(groups = "stu")
    public class GroupsOnClass1 {
    
        public void stu1(){
            System.out.println("GroupsOnClass1中的stu111运行" );
        }
    
        public void stu2(){
            System.out.println("GroupsOnClass1中的stu222运行" );
        }
    
    }
    #GroupsOnClass2
    
    package com.course.testng.groups;
    
    import org.testng.annotations.Test;
    
    @Test(groups = "stu")
    public class GroupsOnClass2 {
    
        public void stu1(){
            System.out.println("GroupsOnClass2中的stu111运行" );
        }
    
        public void stu2(){
            System.out.println("GroupsOnClass2中的stu222运行" );
        }
    }
    #GroupsOnClass3
    
    package com.course.testng.groups;
    
    import org.testng.annotations.Test;
    
    @Test(groups = "teacher")
    public class GroupsOnClass3 {
    
        public void teacher1(){
            System.out.println("GroupsOnClass3中的teacher1111运行" );
        }
    
        public void teacher2(){
            System.out.println("GroupsOnClass3中的teacher2222运行" );
        }
    }
    #groupsOnClass.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <suite name="suitename">
        <test name="runAll">
            <classes>
                <class name="com.course.testng.groups.GroupsOnClass1"/>
                <class name="com.course.testng.groups.GroupsOnClass2"/>
                <class name="com.course.testng.groups.GroupsOnClass3"/>
    
            </classes>
        </test>
    
        <test name="onlyRunStudent">
            <groups>
                <run>
                    <include name="stu"/>
                </run>
            </groups>
            <classes>
                <class name="com.course.testng.groups.GroupsOnClass1"/>
                <class name="com.course.testng.groups.GroupsOnClass2"/>
                <class name="com.course.testng.groups.GroupsOnClass3"/>
    
            </classes>
        </test>
    
    </suite>

    执行结果:(可以看出最下面并没有执行teacher的组。)

    GroupsOnClass1中的stu111运行
    GroupsOnClass1中的stu222运行
    GroupsOnClass2中的stu111运行
    GroupsOnClass2中的stu222运行
    GroupsOnClass3中的teacher1111运行
    GroupsOnClass3中的teacher2222运行
    GroupsOnClass1中的stu111运行
    GroupsOnClass1中的stu222运行
    GroupsOnClass2中的stu111运行
    GroupsOnClass2中的stu222运行

    ===============================================
    suitename
    Total tests run: 10, Failures: 0, Skips: 0
    ===============================================


    Process finished with exit code 0

    说明:

    name = “runAll” 的test,将所有的类里面的测试用例都运行了

    name = “onlyRunStudent” 只是运行了groups=“stu”的类。这是因为在test标签中,添加了以下代码,标志只运行groups的name是“stu”的类中的测试用例。

    <groups>
           <run>
                <include name="stu"/>
           </run>
    </groups>
  • 相关阅读:
    android 开发 View _3_ View的属性动画ValueAnimator
    android 开发 View _2_ View的属性动画ObjectAnimator ,动画效果一览
    android 开发 View _1_ View的子类们 和 视图坐标系图
    android 开发 ScrollView 控件的一些api描述与自定义ScrollView接口回调方法
    android 开发 我的高德地图代码例子
    android 开发 singleTask启动模式下传值的坑
    android 开发 时间选择器TimePicker的使用
    android 开发 实现一个activity变成dialog对话框
    android 开发 实现一个ListView套嵌GirdView的滚动布局
    android 开发 使用自定义布局实现标题栏复用(标题栏内容自定义:使用代码实现和xml布局自定义属性2种办法实现)
  • 原文地址:https://www.cnblogs.com/peiminer/p/9555756.html
Copyright © 2011-2022 走看看