首页/ 学科题库/ maven/ 测试并行与性能优化
maven 实战教程

测试并行与性能优化

2026-05-23 约 10 分钟 juanwangdev

测试并行与性能优化

并行测试大幅缩短测试执行时间。

并行测试配置

XML
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <parallel>classes</parallel>
    <threadCount>4</threadCount>
    <useUnlimitedThreads>false</useUnlimitedThreads>
  </configuration>
</plugin>

parallel 值

值说明
none不并行
methods方法级并行
classes类级并行
both类和方法并行

JUnit 5 并行

配置

XML
<configuration>
  <parallel>methods</parallel>
  <threadCount>4</threadCount>
  <useUnlimitedThreads>false</useUnlimitedThreads>
</configuration>

JUnit 5 junit-platform.properties

properties
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=4

要点总结

  • parallel 配置并行级别
  • threadCount 配置线程数
  • classes 类级并行推荐
  • JUnit 5 需额外 junit-platform.properties 配置
想在手机上练这篇的配套题目?
使用微信 卷王开发者小程序/App,首页顶部扫一扫识别下方二维码,即可解锁本讲对应真题与错题本。
了解产品 App
← 上一篇 测试资源与环境配置 下一篇 → Jenkins 流水线集成