![](/img/trans.png)
[英]How to run surefire tests in parallel while forcing some to run sequentially?
[英]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插件文档 。 它提供了一种通过使用@NotThreadSafe
批注指定某些测试不是线程安全的方法。
另一个解决方案是指定两个单独的surefire执行,其中包含明确的测试包含和排除 。 一个执行可以以并行模式运行,包括线程安全套件,另一个非线程安全。
我们可以通过定义多个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>
是,
将每个顺序测试放在自己的套件中,并将所有并行测试放在一个套件中。 然后设置并行属于类。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.