3 回答
TA贡献1821条经验 获得超5个赞
不能使用 Gradles JUnit 4 运行器为类以外的任何东西并行运行测试。
我无法确认这是否有效,但您可能想尝试 JUnit 5 中的 JUnit Platform + JUnit Vintage。查看JUnit 5 启动器以了解如何设置它。
dependencies {
def junit4Version = '4.12'
def junit5Version = '5.3.2'
implementation(enforcedPlatform("org.junit:junit-bom:${junit5Version}")) {
because 'enforce matching Platform, Jupiter, and Vintage versions'
}
// JUnit Jupiter
testImplementation('org.junit.jupiter:junit-jupiter-api')
testImplementation('org.junit.jupiter:junit-jupiter-params')
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine') {
because 'allows JUnit 5 (read Jupiter) tests to run'
}
// JUnit Vintage
testImplementation("junit:junit:${junit4Version}")
testRuntimeOnly('org.junit.vintage:junit-vintage-engine') {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
}
然后,您可以添加junit.jupiter.execution.parallel.enabled=true以junit-platform.properties启用并行执行。请参阅JUnit 5 用户指南 - 并行执行。
TA贡献1817条经验 获得超6个赞
不幸的是,gradle 仍然不支持这个功能。
PS maxParallelForks 的数量应该以这种方式计算出来:
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
添加回答
举报
