如何参数化Maven surefire插件,以便我可以选择运行哪些TestNG套件 [英] How to parametrize Maven surefire plugin so I can choose which TestNG suites to run

查看:208
本文介绍了如何参数化Maven surefire插件,以便我可以选择运行哪些TestNG套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TestNG中有很多测试套件。这些是XML文件。我希望能够在从maven运行集成测试时选择多个XML套件。

I've got many test suites in TestNG. These are XML files. I want to be able to choose multiple XML suites when running integration-test from maven.

目前我可以将套件文件添加到pom.xml中,如下所示:

Currently I can add the suite files to pom.xml like this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <suiteXmlFiles>
      <suiteXmlFile>${pathToMySuiteFile_1}</suiteXmlFile>
      <suiteXmlFile>${pathToMySuiteFile_1}</suiteXmlFile>
    </suiteXmlFiles>
  </configuration>
</plugin>

此解决方案有一些限制。我只能更改我在pom.xml中定义的测试套件的路径。所以在我的例子中,它总是必须是两个文件。我无法运行,比方说,5套房或只有一套。

This solution has some limitations. I can only change a path to the test suite I've got defined in pom.xml. So in my example it always has to be two files. I'm not able to run, lets say, 5 suites or just one.

有没有办法在pom.xml中以某种方式参数化整个suiteXmlFiles部分?

Is there a way to somehow parametrize the whole section "suiteXmlFiles" in pom.xml ?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <suiteXmlFiles>
      ${multiple_paths_ToMySuiteFiles}
    </suiteXmlFiles>
  </configuration>
</plugin>

运行与给定测试组匹配的所有内容对我来说不是一个选项:
我不喜欢我想加载我已经拥有的所有套件,然后使用TestNG套件中的组运行所选的测试。原因是在运行带有组过滤器的所有测试套件之后生成的报告与仅运行所选测试套件时的报告不同。

Running everything that matches given test group is not an option for me: I don't want to load all the suites I've got and then run just the selected tests using groups in TestNG suite. The reason being that a report that gets generated after running all the test suites with group filters is different from a report when just the selected test suites were run.

推荐答案

根据用户属性 of suiteXmlFiles 您可以使用:

According to User Property of suiteXmlFiles You can use:

mvn test -Dsurefire.suiteXmlFiles=test1.xml,test2.xml

这篇关于如何参数化Maven surefire插件,以便我可以选择运行哪些TestNG套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆