Build 使用TestReport聚合gradle多项目测试结果
我有一个项目结构,如下所示。我想使用Gradle中的功能将所有测试结果聚合到一个目录中。 然后我可以通过一个index.html文件访问所有子项目的所有测试结果。 我怎样才能做到这一点Build 使用TestReport聚合gradle多项目测试结果,build,automated-tests,gradle,Build,Automated Tests,Gradle,我有一个项目结构,如下所示。我想使用Gradle中的功能将所有测试结果聚合到一个目录中。 然后我可以通过一个index.html文件访问所有子项目的所有测试结果。 我怎样才能做到这一点 . |--ProjectA |--src/test/... |--build |--reports |--tests |--index.html (testresults) |--.. |--.. |--ProjectB |--s
.
|--ProjectA
|--src/test/...
|--build
|--reports
|--tests
|--index.html (testresults)
|--..
|--..
|--ProjectB
|--src/test/...
|--build
|--reports
|--tests
|--index.html (testresults)
|--..
|--..
从中:
完整工作样本可从完整的Gradle发行版的
样本/测试/测试报告中获得。对于“connectedAndroidTest”,谷歌发布了一种方法。(多模块报告部分))
将“android reporting”插件添加到projects build.gradle中
应用插件:“android报告”
使用附加的“mergeAndroidReports”参数执行android测试。它将把项目模块的所有测试结果合并到一个报告中
/gradlew已连接AndroidTest合并AndroidReports
除了上面建议的子项目
块和测试报告
任务之外,我还要在构建中添加另一行内容,如下所示:
tasks('test').finalizedBy(testReport)
这样,如果您运行gradletest
(甚至gradlebuild
),则testReport
任务将在子项目测试完成后运行。请注意,您必须使用tasks('test')
而不仅仅是test.finalizedBy(…)
,因为test
任务在根项目中不存在。FYI,我在我的根项目build.gradle
文件中使用以下子项目
配置解决了这个问题。这样就不需要额外的任务
注意:这会将每个模块的输出放在其自己的reports/
文件夹中,因此子项目生成不会覆盖彼此的结果
subprojects {
// Combine all build results
java {
reporting.baseDir = "${rootProject.buildDir.path}/reports/${project.name}"
}
}
对于默认的Gradle项目,这将导致一个文件夹结构,如
build/reports/module_a/tests/test/index.html
build/reports/module_b/tests/test/index.html
build/reports/module_c/tests/test/index.html
如果使用kotlin Gradle DSL
val testReport = tasks.register<TestReport>("testReport") {
destinationDir = file("$buildDir/reports/tests/test")
reportOn(subprojects.map { it.tasks.findByPath("test") })
subprojects {
tasks.withType<Test> {
useJUnitPlatform()
finalizedBy(testReport)
ignoreFailures = true
testLogging {
events("passed", "skipped", "failed")
}
}
}
val testReport=tasks.register(“testReport”){
destinationDir=file($buildDir/reports/tests/test)
reportOn(subprojects.map{it.tasks.findByPath(“test”)})
子项目{
tasks.withType{
useJUnitPlatform()
定稿人(测试报告)
ignoreFailures=true
测试记录{
事件(“已通过”、“跳过”、“失败”)
}
}
}
然后执行gradle testReport
。Source嘿,皮特,我需要一些指导。在我的情况下,我只有一个项目,即ProjectA,在gradle clean build integrationTest之后,我看到build/jacoo/test.exec和build/jacoo/integrationTest.exec。在build/reports/tests/xxxxxx下,我看到index.html用于单元测试,或者只有integrationtests,即如果我运行gradle clean build,我会看到unit tests index.html,如果我运行gradle clean build integrationTest,那么它会覆盖build/reports/tests/xxx中的数据,并在同一文件夹(build/reports/tests)中获取integrationTest任务的新数据。类似地,当我运行sonar runner时,我确实看到在JacoSensor期间拾取了两个.exec文件,我还看到在工作区中的.sonar文件夹和build/reports/jacoo文件夹下创建了整个jacoco.exec。sonar runner成功完成,但我在sonar中的项目仪表板中看不到结果,即使我有这两个wid获取用于显示单元测试/覆盖率和集成测试的设置。请告知我可能缺少的内容。只有test.testReport
属性被弃用。正如弃用消息所述,您只需将其替换为test.reports.html.enabled=false
。我发现,如果一个测试失败,任务报告将无法完成-其余的测试都没有执行,因此需要将ignoreFailures
添加到test
task()。最好使用reportOn getTasksByName(“test”,true)
由于如果某些子项目没有任何测试任务,那么这将起作用,尽管文档说它也可以合并单元测试,但运行此任务依赖于浓缩咖啡测试,这不是我所希望的。我必须执行以下fopr Gradle 5.6.2:rootProject.getTasksByName('test',true')。每个{it.finalizedBy(testReport)}
我看不出这是如何回答问题的。这个问题问的是一个index.html和累积结果。
val testReport = tasks.register<TestReport>("testReport") {
destinationDir = file("$buildDir/reports/tests/test")
reportOn(subprojects.map { it.tasks.findByPath("test") })
subprojects {
tasks.withType<Test> {
useJUnitPlatform()
finalizedBy(testReport)
ignoreFailures = true
testLogging {
events("passed", "skipped", "failed")
}
}
}