等同于Maven Surefire的Gradle surefire.forkNumber [英] Gradle equivalent for Maven Surefire surefire.forkNumber
问题描述
我正在将代码库从Maven迁移到Gradle.
在我们的集成测试中,我们使用FailSafe功能在多个线程中并行运行测试.
FailSafe正在使用当前线程运行的特定fork的编号设置系统属性名称surefire.forkNumber
.
I'm migrating a codebase from Maven to Gradle.
In our integration test we use FailSafe ability to run the tests in parallel in multiple threads.
FailSafe is setting a system property name surefire.forkNumber
with the number of the specific fork the current thread runs.
使用Gradle运行JUnit时是否存在等效的参数?
Is there equivalent parameter when running JUnit with Gradle?
推荐答案
Gradle中的test
任务具有属性maxParallelForks
来指示测试并行运行.
要从命令行传递属性以设置值,我们可以在构建文件中定义以下test
配置:
The test
task in Gradle has the property maxParallelForks
to instruct the tests to run in parallel.
To pass a property from the command-line to set the value we can define the following test
configuration in our build file:
// File: build.gradle
...
// Set maxParallelForks using project property
// testMaxParallelForks if set otherwise use 1.
test.maxParallelForks = project.findProperty('testMaxParallelForks') ?: 1
...
然后从命令行运行test
任务:$ gradle test -PtestMaxParallelForks=8
Then from the command-line we can run the test
task: $ gradle test -PtestMaxParallelForks=8
Gradle用运行测试的线程的索引号设置Java System属性org.gradle.test.worker
.可以在并行线程上运行的测试中读取和使用此属性.
Gradle sets the Java System property org.gradle.test.worker
with the index number of the thread running the test. This property can be read and used within the tests that run on the parallel thread.
这篇关于等同于Maven Surefire的Gradle surefire.forkNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!