当前位置: 首页 > news >正文

JUnit5用户手册~并行执行

两种运行模式

SAME_THREAD:默认的,测试方法在同一个线程
CONCURRENT:并行执行,除非有资源锁

junit-platform.properties配置参数

配置所有测试方法都并行

junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
@Execution(CONCURRENT)指定类或方法并行

配置top-level类并行,测试方法同一线程执行

junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = same_thread
junit.jupiter.execution.parallel.mode.classes.default = concurrent

配置top-level类串行,测试方法并行

junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = same_thread

 相关参数

属性

描述

支持的值默认值
junit.jupiter.execution.parallel.enabled
是否允许并行

true

false

false
junit.jupiter.execution.parallel.mode.default
test tree的默认执行模式
concurrent
same_thread
same_thread
junit.jupiter.execution.parallel.mode.classes.default
top-level类的默认执行模式
concurrent
same_thread
same_thread
junit.jupiter.execution.parallel.config.strategy
默认线程和最大线程数的策略
dynamic
fixed
custom
dynamic
junit.jupiter.execution.parallel.config.dyna mic.factor

 dynamic配置的系数

数值1
junit.jupiter.execution.parallel.config.fixed.parallelism
fixed配置的线程数数值无默认
junit.jupiter.execution.parallel.config.custom.class
custom配置的策略类无默认

2、同步

@Execution(CONCURRENT)
class SharedResourcesDemo {private Properties backup;@BeforeEachvoid backup() {backup = new Properties();backup.putAll(System.getProperties());}@AfterEachvoid restore() {System.setProperties(backup);}@Test@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ)void customPropertyIsNotSetByDefault() {assertNull(System.getProperty("my.prop"));}@Test@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ_WRITE)void canSetCustomPropertyToApple() {System.setProperty("my.prop", "apple");assertEquals("apple", System.getProperty("my.prop"));}@Test@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ_WRITE)void canSetCustomPropertyToBanana() {System.setProperty("my.prop", "banana");assertEquals("banana", System.getProperty("my.prop"));}
}

http://www.lryc.cn/news/44962.html

相关文章:

  • 【从零开始学习 UVM】3.3、UVM TestBench架构 —— UVM Environment [uvm_env]
  • Vue的简单介绍
  • 我给Chat GPT写了个记忆系统
  • 哈希表题目:砖墙
  • 【程序环境详解】
  • 栈(Stack)
  • 【计算机网络】2、网络编程模型理论
  • jmeter接口测试及详细步骤以及项目实战教程
  • 抖音进攻,B站退守
  • 2022国赛E题完整成品文章数据代码模型--小批量物料的生产安排
  • 学生党,快来 Azure 一起学习 OpenAI (一):注册 Azure 和申请 OpenAI
  • 深入理解【正则化的L1-lasso回归和L2-岭回归】以及相关代码复现
  • 入侵检测——如何实现反弹shell检测?
  • Python常用语句学习
  • 测试3年还不如应届生,领导一句点醒:“公司不是只雇你来点点点的”
  • 华为网络设备之路由策略,前缀列表(使用,规则)
  • 白噪音简介与实现
  • Springboot结合线程池的使用
  • AOP工作流程
  • Modbus相关知识点及问题总结
  • 【MySQL】函数
  • MySQL高级
  • 带你弄明白c++的4种类型转换
  • 8个明显可以提升数据处理效率的 Python 神库
  • 互联网公司吐槽养不起程序员,IT岗位的工资真是虚高有泡沫了?
  • Excel 进阶|只会 Excel 也能轻松搭建指标应用啦
  • RabbitMQ中TTL
  • Ceres简介及示例(4)Curve Fitting(曲线拟合)
  • 音质最好的骨传导蓝牙耳机有哪些,推荐几款不错的骨传导耳机
  • 计算机操作系统安全