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

发表于:2017-9-26 16:19

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:佚名    来源:51Testing软件测试网采编

  实际生产环境的测试工程都包含多个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的功能
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号