【问题标题】:Run gradle spock test task in parallel并行运行 gradle spock 测试任务
【发布时间】:2021-08-02 07:36:13
【问题描述】:

在我的build.gradle 我有以下测试任务

task test1(type: Test) {
    ignoreFailures true
    testLogging {
        events 'started', 'passed', 'skipped', 'failed'
        exceptionFormat "full"
        showStandardStreams = true

        afterSuite { desc, result ->
            if (!desc.parent) { // will match the outermost suite
                failedTest += result.failedTestCount
            }
        }
    }
    include "org/company/project/test/Test1.class"
}

task test2(type: Test) {
    ignoreFailures true
    testLogging {
        events 'started', 'passed', 'skipped', 'failed'
        exceptionFormat "full"
        showStandardStreams = true

        afterSuite { desc, result ->
            if (!desc.parent) { // will match the outermost suite
                failedTest += result.failedTestCount
            }
        }
    }
    include "org/company/project/test/Test2.class"
}

我希望这两个测试并行运行,目前我使用这个命令来运行它们./gradlew cleanTest test1 test2 --info --rerun-tasks命令来运行它们。

我试过--parallel--max-workers=3 选项没有任何帮助。

【问题讨论】:

    标签: testing gradle parallel-processing spock


    【解决方案1】:

    Gradle 不支持在同一个项目中并行运行任务,除非您获得configuration cache 命中,但这是一个孵化功能,它可能不适合您。

    你有什么理由不在测试任务中使用分叉(docs)?

    test {    
      maxParallelForks = 3
    }
    

    或用于所有测试任务

    tasks.withType(Test) {
        maxParallelForks = 3
    }
    

    【讨论】:

    • 这个没用,我之前试过这个,执行时间没有改善
    猜你喜欢
    • 1970-01-01
    • 2014-07-11
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多