使用 gradle 运行并行测试任务 [英] Run parallel test task using gradle
问题描述
我们使用 JUnit 作为测试框架.我们有很多项目.我们使用 gradle(1.12 版)作为构建工具.为了使用 gradle 并行运行单元测试,我们在每个测试任务中使用以下脚本.
We use JUnit as a test framework. We have many projects. We use gradle (version 1.12) as a build tool. To run the unit tests in parallel using gradle we use the below script in every project under test task.
maxParallelForks = Runtime.runtime.availableProcessors()
例如:
test {
maxParallelForks = Runtime.runtime.availableProcessors()
}
我们还维护单个 gradle.properties 文件.
We also maintain the single gradle.properties file.
是否可以在 gradle.properties 文件中定义 test.maxParallelForks = Runtime.runtime.availableProcessors() 而不是在测试任务下的每个 build.gradle 文件中定义它?
Is it possible to define test.maxParallelForks = Runtime.runtime.availableProcessors() in gradle.properties file rather than defining it in each build.gradle file under test task?
推荐答案
$rootDir/build.gradle
:
subprojects {
tasks.withType(Test) {
maxParallelForks = Runtime.runtime.availableProcessors()
}
}
这篇关于使用 gradle 运行并行测试任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!