我有一个带有surefire:test插件的pom.xml文件,并有两个配置文件来运行不同的测试模块/测试。我试图通过命令来运行这些命令" mvn surefire:test -PfirstProfile,secondProfile"。 但是这里只有pom.xml中编写的第二个配置文件被执行。 apache maven网站推荐此命令。这是我的pom.xml文件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.plugin.surefire.version}</version>
<configuration>
<forkMode>always</forkMode>
<!-- <testFailureIgnore>true</testFailureIgnore> -->
<failIfNoTests>false</failIfNoTests>
<skipTests>${skipTests}</skipTests>
<runOrder>${testRunOrder}</runOrder>
</configuration>
</execution>
</executions>
</plugin>
<profile>
<id>firstProfile</id>
<properties>
<skipTests>false</skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.plugin.surefire.version}</version>
<configuration>
<includes>
<include>**/AbcTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>SecondProfile</id>
<properties>
<skipTests>false</skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.plugin.surefire.version}</version>
<configuration>
<includes>
<include>**/xyzTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
那么如何将这两个配置文件一起运行?我也试过了执行ID。但它没有用。
答案 0 :(得分:0)
尝试在两个配置文件中更改maven-surefire-plugin的配置,如下所示:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.plugin.surefire.version}</version>
<configuration>
<includes combine.children="append">
<include>**/AbcTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
除此之外,按配置文件选择单元测试并不是一个好主意。如果这些测试是集成测试,那么你应该使用maven-failsafe-plugin。