美文网首页
[TestNG]TestNG运行指定测试套件testng.xml

[TestNG]TestNG运行指定测试套件testng.xml

作者: 测试你个头 | 来源:发表于2017-09-12 11:43 被阅读0次

    TestNG系列:
    TestNG和Junit4的参数化测试对比
    TestNG运行指定测试套件
    TestNG整合ReportNG
    TestNG参数化测试实战
    TestNG+Spring/Spring Boot整合

    实际生产环境的测试工程都包含多个suite,并通过不同的suite将测试类组织起来,实际应用过程中,在具体的场景下往往只需要运行其中的一个suite。

    1.为不同的suite创建不同的testng.xml:

    2.TestNG可以通过配置suiteXmlFile指定需要运行的testng.xml:

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    

    3.如果需要运行测试,在终端执行命令即可:

    cd test-project/
    mvn -B test -Dmaven.test.failure.ignore=true
    

    4.如果想通过命令行运行指定的suite,可以通过如下方式实现:

    • 在test-project下新建一个shell脚本(run.sh)
      这里$1是脚本的命令行参数
    cd test-project/
    rm -f src/test/resources/tesng.xml
    cp -af src/test/resources/testng-$1.xml src/test/resources/tesng.xml
    mvn -B test -Dmaven.test.failure.ignore=true
    
    • 通过运行run.sh的方法运行测试:
    bash run.sh workshift
    

    这样就可以实现通过命令行运行制定suite的功能

    相关文章

      网友评论

          本文标题:[TestNG]TestNG运行指定测试套件testng.xml

          本文链接:https://www.haomeiwen.com/subject/qbhpjxtx.html