本文转自测试人社区,原文链接: https://ceshiren.com/t/topic/28207
环境配置
用例准备
无并发
- 如果没有并发配置,默认就是主「
main
」线程运行。
并行步骤
- 配置并行测试的
parallel
参数。
junit.jupiter.execution.parallel.enabled
的值设置为true
。
- 注意:启用此属性只是并行执行测试所需的第一步。
- 如果启用,默认情况下++测试类和方法仍将按顺序执行++。
parallel配置
- 在
JUnit5
的配置文件「junit-platform.properties
」进行配置 (最简单的方法)junit.jupiter.execution.parallel.enabled=true
- 通过向
maven surefire
插件提供参数 - 通过向
JVM
提供系统属性
1.JUnit5配置文件创建
- 在项目的
src/test/resources
目录下创建JUnit5
的配置文件:junit-platform.properties
2.并行测试配置
- 以下配置放入JUnit5配置文件中:
junit.jupiter.execution.parallel.enabled=true
3.运行
- 命令行进入到当前项目路径,输入
mvn clean test
,运行结果如下:
结论
- 测试按顺序运行
- 使用ForkJoin线程池