两种运行模式
配置所有测试方法都并行
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = 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配置的系数文章来源:https://www.toymoban.com/news/detail-417764.html |
数值 | 1 |
junit.jupiter.execution.parallel.config.fixed.parallelism
|
fixed配置的线程数 | 数值 | 无默认 |
junit.jupiter.execution.parallel.config.custom.class
|
custom配置的策略类 | 类 | 无默认 |
2、同步文章来源地址https://www.toymoban.com/news/detail-417764.html
@Execution(CONCURRENT)
class SharedResourcesDemo {
private Properties backup;
@BeforeEach
void backup() {
backup = new Properties();
backup.putAll(System.getProperties());
}
@AfterEach
void 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"));
}
}
到了这里,关于JUnit5用户手册~并行执行的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!