2019年android多模块gradle项目如何聚合测试报告

问题描述 投票:0回答:1

我有一个多模块 Android gradle 项目。

project
  |- app
  |- module1
  |- module2

每个模块都包含单元测试,

app
模块还包含仪表测试。我不想从模块中获取 xml 报告,而是将它们存储在一个地方,例如
/build/tests/reports

到目前为止我尝试实现的是将报告目录设置为此路径

android {
    testOptions {
        resultsDir "$rootDir/build/test/results"
        reportDir "$rootDir/build/test/reports"
    }
}

我将其应用到了模块的所有 gradle 文件中。但这似乎只适用于仪器/

connected
测试报告。我怎样才能在单元测试中实现这一目标?

android unit-testing testing android-gradle-plugin multi-module
1个回答
0
投票

律动

task testReport(type: TestReport) {
  destinationDir = file("$buildDir/reports/allTests")
  // Combine all 'test' task results into a single HTML report
  reportOn subprojects.collect { it.tasks.withType(Test) }
}

Kotlin DSL(已测试)

tasks.register<TestReport>("testReport") {
destinationDirectory.set(file("$rootDir/reports/tests/unitTest"))
// Combine all 'test' task results into a single HTML report
testResults.from(subprojects.flatMap { it.tasks.withType(Test::class) })
}

然后执行

./gradlew testReport

注意:将其添加到项目级别

build.gradle
而不是模块级别。

© www.soinside.com 2019 - 2024. All rights reserved.