测试报告聚合插件(插件 ID:test-report-aggregation
)提供了用于将多个 Test 任务调用(可能跨越多个 Gradle 项目)的结果聚合到一个 HTML 报告中的任务和配置。
用法
要使用测试报告聚合插件,请在您的构建脚本中包含以下内容
plugins { id 'test-report-aggregation' }
plugins { id("test-report-aggregation") }
请注意,除非与 JVM 测试套件插件结合使用,否则此插件不会执行任何操作。Java 插件会自动应用 JVM 测试套件插件。
现在有两种方法可以在多个子项目中收集测试结果
示例 2 也可以用于通过根项目聚合结果。
测试报告聚合插件目前不适用于 com.android.application 插件。 |
任务
当项目也应用了 jvm-test-suite
插件时,会为每个测试套件添加以下任务
testSuiteAggregateTestReport
— TestReport-
依赖于:匹配以下属性的变体的工件
通过
testReportAggregation
配置收集直接和传递项目依赖项的变体。将匹配以下属性
- org.gradle.category = verification (1)
- org.gradle.testsuite.name = test (2)
- org.gradle.verificationtype = test-results (3)
1 | Category 属性;值是固定的。 |
2 | TestSuiteName 属性;值派生自 TestSuite#getName()。 |
3 | VerificationType 属性;值是固定的。 |
有关测试执行生成的变体的更多信息,请参阅 JVM 测试套件插件文档的输出变体部分。
报告
默认情况下,当任何任务失败(包括测试失败)时,Gradle 会停止执行任务。为了确保您的构建始终生成聚合报告,请在 Gradle 命令中指定 |
自动报告创建
当项目也应用了 jvm-test-suite
插件时,会为每个测试套件添加以下报告对象
testSuiteAggregateTestReport
— AggregateTestReport-
创建一个聚合 Jacoco 报告,聚合所有项目依赖项中具有给定名称的所有测试套件。
手动报告创建
当项目不应用 jvm-test-suite
插件时,您必须手动注册一个或多个报告
示例 1. 创建报告容器
build.gradle.kts
reporting {
reports {
val testAggregateTestReport by creating(AggregateTestReport::class) { (1)
testSuiteName = "test"
}
}
}
build.gradle
reporting {
reports {
testAggregateTestReport(AggregateTestReport) { (1)
testSuiteName = "test"
}
}
}
1 | 创建一个名为 testAggregateTestReport 的 AggregateTestReport 类型的报告,聚合所有项目依赖项中具有给定 TestSuite#getName() 的所有测试套件。 |
报告创建会自动创建支持任务,以按给定的测试套件类型值进行聚合。