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

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的功能

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容