如何聚合多个项目使用不同插件的测试报告?

12

如何遍历每个不同类型项目的测试结果并将其收集在单个报告中?

示例项目设置:

Root Project
    |
    |- Java Project
    |- test task
    |
    |- Android Library Project (has Build Types)
    |- testDebug task
    |- testRelease task
    |
    |- Android application Project (has Product Flavors and Build Types)
    |- testFreeDebug task
    |- testFreeRelease task
    |- testPaidDebug task
    |- testPaidRelease task

目前为止我所拥有的:

这将汇总所有项目的测试结果:

task aggregateResults(type: Copy) {
    outputs.upToDateWhen { false }
    subprojects { project ->
        from { project*.testResultsDir }
    }
    into { file("$rootDir/$buildDir/results") }
}

task testReport(type: TestReport) {
    outputs.upToDateWhen { false }
    destinationDir = file("$rootDir/$buildDir/reports/allTests")
    subprojects { project ->
        reportOn project.tasks.withType(Test)*.binResultsDir
    }
}

参考文献:

仅适用于Java:

task testReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/allTests")
    reportOn subprojects*.test
}

来源:https://dev59.com/HGQn5IYBdhLWcg3wVF0w#16921750

仅适用于Android:

subprojects.each { subproject -> evaluationDependsOn(subproject.name) }

def testTasks = subprojects.collect { it.tasks.withType(Test) }.flatten()

task aggregateResults(type: Copy) {
    from { testTasks*.testResultsDir }
    into { file("$buildDir/results") }
}

来源:https://android.googlesource.com/platform/tools/build/+/nougat-release/build.gradle#79


为什么被踩了票? - Jared Burrows
你好!你找到解决方案了吗? - Viktoriia Chebotar
@ViktoriiaChebotar 不。 - Jared Burrows
1个回答

2

该解决方案仅在任务准备就绪时向报告中添加特定任务。可应用于像您的异构/特定任务等情况。

subprojects {
    // Add custom tasks as part of report when it ready
    gradle.taskGraph.whenReady { graph ->
        if (graph.hasTask(testDebugUnitTest)) {
            rootTestReport.reportOn(testDebugUnitTest)
        }
        // and so on
    }
}

// Combine all 'test' task results into a single HTML report
tasks.register('rootTestReport', TestReport) {
    subprojects.each { dependsOn("${it.name}:testDebugUnitTest") } // todo: to be improved
    destinationDir = file("$buildDir/reports/allTests")
}

这对我有用,非常感谢! - ansh sachdeva

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接