[英]Configuring a Maven plugin twice in a pom.xml
我正在一个大型Maven
Java项目中,该项目包含TestNG
自动化测试套件以及Cucumber
自动化测试套件。 我意识到这并不理想,但是不同的测试套件是由不同子团队在项目的不同阶段编写的。 展望未来,我们打算将这个项目分成几个较小的项目,但是目前我们仍然束手无策。
surefire
插件可用于从Maven
运行这些测试,但是需要为pom.xml
每个插件配置不同的插件。
对于Cucumber
,我们将其与Cucumber
cucumber-jvm-parallel-plugin
结合使用,并且其配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<forkCount>${threads}</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/Parallel*IT.class</include>
</includes>
</configuration>
</plugin>
对于我们的TestNG
测试,它的配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>${file}</suiteXmlFiles>
<skipTests>false</skipTests>
<properties>
<property>
<name>suitethreadpoolsize</name>
<value>${threads}</value>
</property>
</properties>
</configuration>
</plugin>
我们不是Maven
专家,因此,目前,我们只是注释掉不想用于正在运行的套件的插件版本。 显然,这很麻烦,而且不是最佳做法,因此,对于我们应该如何解决此问题的任何建议,我将不胜感激。 我们能否在pom.xml中两次合法地定义插件,并以某种方式传递一个标志来指示应该运行哪个版本? 非常感谢您阅读我的问题。
使用Maven配置文件选择正确的配置:
添加以下代码段:
<profiles>
<profile>
<id>Cucumber</id>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>${threads}</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/Parallel*IT.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</profile>
<profile>
<id>TestNG</id>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>${file}</suiteXmlFiles>
<properties>
<property>
<name>suitethreadpoolsize</name>
<value>${threads}</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</profile>
</profiles>
并改变这个
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<!-- delete on of the entries -->
</plugins>
您必须在命令行中指定所需的配置文件:
mvn test -P Cucumber
mvn test -P TestNG
您也可以同时运行两者:
mvn test -P Cucumber -P TestNG
mvn test -P Cucumber,TestNG
为要运行的每组测试创建一个下游Maven项目。 前面还有更多工作要做,但很快就会收到回报。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.