• TestNG系列(三)TestNG之XML文件配置


    前言

    上一篇博客说了TestNG的注解,这篇博客来介绍Test.xml文件。

    Test.xml文件可以更方便的管理和执行测试用例

    一、Test.xml-suite:

    suite为Test.xml的根节点

    @name: suite的名称,必须参数,会体现在测试报告中。
    @parallel:是否多线程并发运行测试
    @configfailurepolicy:一旦Before/After Class/Methods这些方法失败后,是继续执行测试还是跳过测试;可选值 (skip | continue),默认"skip"
    @skipfailedinvocationcounts:是否跳过失败的调用,可选值(true | false),默认"false"
    @object-factory:一个实现IObjectFactory接口的类,用来实例测试对象
    @preserve-order:顺序执行开关,可选值(true | false) "true"
    @group-by-instances:是否按实例分组,可选值(true | false) "false"

    二、Test.xml-test:

    @name:test的名字,必选参数,会体现在测试报告中。
    @parallel:是否多线程并发运行测试
    @enabled:设置当前test是否生效,可选值(true | false),默认"true"
    @skipfailedinvocationcounts:是否跳过失败的调用,可选值(true | false),默认"false"
    @preserve-order:顺序执行开关,可选值(true | false) "true"
    @group-by-instances:是否按实例分组,可选值(true | false) "false"

    三、全局参数Parameter

    此属性在xml文件不是非必要的属性,如果测试用例中有使用@Parameter定义的参数,则需要填写此属性。

    xml文件

    <parameter name="url" value="https://www.baidu.com" />
    <parameter name="data" value="全局变量" />

    测试用例

    @Parameters({"url","data"})
    @Test
    public void test_case2_1(String url,String data){}

    四、调用测试方法

    调用测试类:执行com.selenium.TestNGcase.testcase2类中所有@Test方法

    <?xml version="1.0" encoding="UTF-8"?>
    <suite name="Selenium-测试脚本集" parallel="none">
        
        <test name="Selenium+TestNG">
            <classes>
                <!-- 执行中的所有@test方法 -->
                <class name="com.selenium.TestNGcase.testcase2" /> 
            </classes>
        </test>
    </suite>

    调用测试类中的具体方法:执行com.selenium.TestNGcase.testcase2类中方法名为test_case_2_1的测试方法

    <?xml version="1.0" encoding="UTF-8"?>
    <suite name="Selenium-测试脚本集" parallel="none">
        
        <test name="Selenium+TestNG">
            <classes>
                <class name="com.selenium.TestNGcase.testcase2">
                    <methods>
                        <include name="test_case_2_1"></include>
                    </methods>
                </class>
            </classes>
        </test>
    </suite>

    组测试

    xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <suite name="Selenium-测试脚本集" parallel="none">    
        <test name="Selenium+TestNG">
            <groups>
                <run>
                    <include name = "yuhao" />
                </run>
                <classes>
                    <class name = "com.selenium.TestNGcase.testcase2" />
                </classes>
            </groups>
        </test>
    </suite>

    测试用例

    @Test(groups="yuhao")
        public void test_case2_1(String url,String data) throws InterruptedException{
            
    }
        
    @Test(groups="yuhao")
    public void test_case2_2(){
        System.out.println("test_case2_2");
    }

    五、Suite-files

    由于testng.xml中只能设置一个<suite>标签,通过<suite-files >标签可以实现允许多个测试集一起执行。

    <?xml version="1.0" encoding="UTF-8"?>
    <suite name="Selenium">
    
        <suite-files>
            <!--模块1-->
            <suite-file path="TestNG_1.xml"></suite-file>
    
            <!--模块2-->
            <suite-file path="TestNG_2.xml"></suite-file>
    
        </suite-files>
    
    </suite>
  • 相关阅读:
    Python制作回合制手游外挂简单教程(中)
    软件工程知识大纲
    Android应用程序开发
    Python制作回合制手游外挂简单教程(上)
    操作系统概念大纲
    Java三种工厂模式
    Java泛型的理解
    Java动态代理的理解
    编译原理与技术大纲
    新服务器sudo与权限分配<NIOT>
  • 原文地址:https://www.cnblogs.com/yogouo/p/11946908.html
Copyright © 2020-2023  润新知