全部学科
Python全栈
python
NodeJS全栈
nodejs
📅 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 配置
想在手机上练习这篇文章的配套题目?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码
← 上一篇 测试资源与环境配置
下一篇 → Jenkins 流水线集成
扫码体验小程序
加载中
想在手机上刷题学习?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码