在pom.xml中配置两次Maven插件



我正在处理一个大型MavenJava项目,该项目包含TestNG自动化测试套件和Cucumber自动化测试套件。我意识到这并不理想,但不同的测试套件是由不同的子团队在项目的不同阶段编写的。展望未来,我们打算将这个项目拆分为更小的项目,但目前我们仍停留在这种组合中。

surefire插件可以用于从Maven运行这些测试,但在我们的pom.xml中,需要对每个插件进行不同的配置。

对于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项目。前面有更多的工作,但很快就会有回报。

最新更新