Surefire 运行 某些测试顺序进行,其他测试并行进行
Surefire run certain tests in sequence, others in parallel
有没有办法按照 JUnit 的 surefire 插件顺序进行某些测试 运行?目前它运行并行所有测试,但有些测试很难转换,如果它们不运行并行就足够了。这是我们的一部分 pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
<configuration>
<parallel>all</parallel>
<threadCount>8</threadCount>
<includes>
<include>${includeTest}</include>
<include>${includeAdditionalTest}</include>
</includes>
</configuration>
</plugin>
请参阅 surefire plugin documentation。它提供了一种通过使用 @NotThreadSafe
注释来指定某些测试不是线程安全的方法。
另一种解决方案是使用显式 test inclusions and exclusions 指定两个单独的 surefire 执行。一个执行可以 运行 在并行模式下,包括线程安全套件,另一个是非线程安全套件。
是的,
将每个顺序测试放在自己的套件中,并将所有并行测试放在一个套件中。然后设置并行属性为类.
<configuration>
<includes>
<include>**/A01TestSuite.java</include>
<include>**/A02ServiceTestSuite.java</include>
<include>**/A03FlowTestSuite.java</include>
</includes>
<additionalClasspathElements>
<additionalClasspathElement>${webinf.dir
</additionalClasspathElement>
</additionalClasspathElements>
<systemPropertyVariables>
<log4j.configuration>file:${l4j.test}/log4j.test.properties</log4j.configuration>
</systemPropertyVariables>
<forkMode>always</forkMode>
<argLine>-Xms512m -Xmx512m</argLine>
<parallel>classes</parallel>
<threadCount>10</threadCount>
</configuration>
我们可以通过定义多个executions
来实现
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>unit-test</id>
<phase>unit-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<parallel>methods</parallel>
<threadCount>4</threadCount>
<perCoreThreadCount>true</perCoreThreadCount>
<excludes>
<!-- run all UTs (non-ITs) parallel -->
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<!-- run integration tests sequentially -->
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
有没有办法按照 JUnit 的 surefire 插件顺序进行某些测试 运行?目前它运行并行所有测试,但有些测试很难转换,如果它们不运行并行就足够了。这是我们的一部分 pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.17</version>
</dependency>
</dependencies>
<configuration>
<parallel>all</parallel>
<threadCount>8</threadCount>
<includes>
<include>${includeTest}</include>
<include>${includeAdditionalTest}</include>
</includes>
</configuration>
</plugin>
请参阅 surefire plugin documentation。它提供了一种通过使用 @NotThreadSafe
注释来指定某些测试不是线程安全的方法。
另一种解决方案是使用显式 test inclusions and exclusions 指定两个单独的 surefire 执行。一个执行可以 运行 在并行模式下,包括线程安全套件,另一个是非线程安全套件。
是的,
将每个顺序测试放在自己的套件中,并将所有并行测试放在一个套件中。然后设置并行属性为类.
<configuration>
<includes>
<include>**/A01TestSuite.java</include>
<include>**/A02ServiceTestSuite.java</include>
<include>**/A03FlowTestSuite.java</include>
</includes>
<additionalClasspathElements>
<additionalClasspathElement>${webinf.dir
</additionalClasspathElement>
</additionalClasspathElements>
<systemPropertyVariables>
<log4j.configuration>file:${l4j.test}/log4j.test.properties</log4j.configuration>
</systemPropertyVariables>
<forkMode>always</forkMode>
<argLine>-Xms512m -Xmx512m</argLine>
<parallel>classes</parallel>
<threadCount>10</threadCount>
</configuration>
我们可以通过定义多个executions
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>unit-test</id>
<phase>unit-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<parallel>methods</parallel>
<threadCount>4</threadCount>
<perCoreThreadCount>true</perCoreThreadCount>
<excludes>
<!-- run all UTs (non-ITs) parallel -->
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<!-- run integration tests sequentially -->
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>