[英]How to parametrize Maven surefire plugin so I can choose which TestNG suites to run
I've got many test suites in TestNG. 我在TestNG中有很多测试套件。 These are XML files. 这些是XML文件。 I want to be able to choose multiple XML suites when running integration-test from maven. 我希望能够在从maven运行集成测试时选择多个XML套件。
Currently I can add the suite files to pom.xml like this: 目前我可以将套件文件添加到pom.xml,如下所示:
<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>
This solution has some limitations. 该解决方案有一些局限性。 I can only change a path to the test suite I've got defined in pom.xml. 我只能更改我在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. 我不能跑,比方说,5套房或只有一套。
Is there a way to somehow parametrize the whole section "suiteXmlFiles" in pom.xml ? 有没有办法以某种方式参数化pom.xml中的整个“suiteXmlFiles”部分?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
${multiple_paths_ToMySuiteFiles}
</suiteXmlFiles>
</configuration>
</plugin>
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. 运行与给定测试组匹配的所有内容对我来说不是一个选项:我不想加载我所拥有的所有套件,然后使用TestNG套件中的组运行所选的测试。 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. 原因是在运行具有组过滤器的所有测试套件之后生成的报告与仅运行所选测试套件时的报告不同。
根据suiteXmlFiles
用户属性 ,您可以使用:
mvn test -Dsurefire.suiteXmlFiles=test1.xml,test2.xml
We also hit this issue with our tests. 我们的测试也遇到了这个问题。 The current workaround that we use now is to define a property variable in the property section and inject it in sure-fire suiteXmlFiles block. 我们现在使用的当前解决方法是在属性部分中定义属性变量,并将其注入到sure-fire suiteXmlFiles块中。
<properties>
<!-- Default suites -->
<batsSuiteFile>${project.build.testOutputDirectory}/BatsTests.xml</batsSuiteFile>
<smokeSuiteFile>${project.build.testOutputDirectory}/SmokeTests.xml</smokeSuiteFile>
<!-- Default suite files if not being specified from mvn command line -->
<defaultSuiteFiles>${batsSuiteFile},${smokeSuiteFile}</defaultSuiteFiles>
<suiteFile>${defaultSuiteFiles}</suiteFile>
</properties>
Then in the plugin section... 然后在插件部分......
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<suiteXmlFiles>
<!-- Suite file injection parameter from command line -->
<suiteXmlFile>${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
If nothing is specified from the command line it will fall back and default to the 2 suites specified above in the properties section. 如果从命令行中未指定任何内容,则它将退回并默认为属性部分中上面指定的2个套件。 Then if you want to kick off a specified set of suite files you can do: 然后,如果您想启动一组指定的套件文件,您可以执行以下操作:
mvn test -DsuiteFile=test1.xml,test2.xml
Surprisingly from the maven docs you expect that the arg suiteXmlFiles should just override this from the command line and should just accept a comma delimited list of testng xmls http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#suiteXmlFiles 令人惊讶的是,maven docs你希望arg suiteXmlFiles应该从命令行覆盖它,并且应该只接受逗号分隔的testng xmls列表http://maven.apache.org/plugins/maven-surefire-plugin/test- mojo.html#suiteXmlFiles
If anyone has any other better way please share. 如果有人有任何其他更好的方式请分享。
You can use groups parameter or specify -Dgroups=... in the command line: 您可以在命令行中使用groups参数或指定-Dgroups = ...:
(TestNG/JUnit47 provider with JUnit4.8+ only) Groups for this test. (仅限JUnit4.8 +的TestNG / JUnit47提供程序)此测试的组。 Only classes/methods/etc decorated with one of the groups specified here will be included in test run, if specified. 如果指定,只有在此处指定的组之一装饰的类/方法/等将包含在测试运行中。 For JUnit, this parameter forces the use of the 4.7 provider This parameter is ignored if the suiteXmlFiles parameter is specified. 对于JUnit,此参数强制使用4.7提供程序如果指定了suiteXmlFiles参数,则忽略此参数。 . 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.