Jacoco 数据文件对于 TeamCity 上的 Android 不可读
Jacoco data file not readable for Android on TeamCity
我今天正在学习 TeamCity Integration Server,我正在尝试使用基于 Android Gradle 的应用程序启用 Jococo Reports。
This 文档向我展示了如何启用 Jococo 覆盖,并出现以下警告:
确保您的测试 运行 在 fork=true 模式下。否则可能无法正确收集覆盖率数据。
我不知道我应该如何处理 "run my tests in fork=true mode"。 TeamCity 未生成覆盖率报告,并通过以下日志警告我:
Jacoco data file path specified as C:\TeamCity\buildAgent\temp\buildTmp\JACOCO5884661263301729570coverage\jacoco.exec but is not readable. Coverage will not be collected.
我认为此警告与未在 fork=true 模式下 运行ning 测试有关。
那么,我的问题是:
- 什么 fork=true 模式意味着什么
- 如何在gradle启用它?
谢谢!!!
您可能要考虑使用 Gradle jacoco plugin。这具有消除对 CI 基础架构的任何依赖的额外好处,允许您对开发人员机器进行 运行 覆盖率报告。
经过一些研究,我能够指示 Teamcity 使用“服务消息”技术来处理由 jacoco 生成的覆盖率报告,在 this 上进行了解释:
Since TeamCity 9.0, TeamCity is able to parse JaCoCo coverage data and generate a report using a service message of the following format:
##teamcity[jacocoReport dataPath='<path to jacoco.exec file>']
因此,我修改了我的 build.gradle 文件,将以下行添加到 jacocoTestReport
部分:
if (project.hasProperty("teamcity")) {
println '##teamcity[jacocoReport dataPath=\'app/build/jacoco/testDebug.exec\' includes=\'com.mynamespace.myproject.*\' excludes=\'**/R.class **/R$*.class **/*$ViewInjector*.* **/BuildConfig.* **/Manifest*.*\']'
}
在那之后,完整的jacocoTestReport
是:
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
classDirectories = fileTree(
dir: '../app/build/intermediates/classes/debug',
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*']
)
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files('../app/build/jacoco/testDebug.exec')
if (project.hasProperty("teamcity")) {
println '##teamcity[jacocoReport dataPath=\'app/build/jacoco/testDebug.exec\' includes=\'com.mynamespace.myproject.*\' excludes=\'**/R.class **/R$*.class **/*$ViewInjector*.* **/BuildConfig.* **/Manifest*.*\']'
}
reports {
xml.enabled = true
html.enabled = true
}
}
Teamcity 开始报告 CodeCoverage 如下:
我今天正在学习 TeamCity Integration Server,我正在尝试使用基于 Android Gradle 的应用程序启用 Jococo Reports。
This 文档向我展示了如何启用 Jococo 覆盖,并出现以下警告:
确保您的测试 运行 在 fork=true 模式下。否则可能无法正确收集覆盖率数据。
我不知道我应该如何处理 "run my tests in fork=true mode"。 TeamCity 未生成覆盖率报告,并通过以下日志警告我:
Jacoco data file path specified as C:\TeamCity\buildAgent\temp\buildTmp\JACOCO5884661263301729570coverage\jacoco.exec but is not readable. Coverage will not be collected.
我认为此警告与未在 fork=true 模式下 运行ning 测试有关。
那么,我的问题是:
- 什么 fork=true 模式意味着什么
- 如何在gradle启用它?
谢谢!!!
您可能要考虑使用 Gradle jacoco plugin。这具有消除对 CI 基础架构的任何依赖的额外好处,允许您对开发人员机器进行 运行 覆盖率报告。
经过一些研究,我能够指示 Teamcity 使用“服务消息”技术来处理由 jacoco 生成的覆盖率报告,在 this 上进行了解释:
Since TeamCity 9.0, TeamCity is able to parse JaCoCo coverage data and generate a report using a service message of the following format:
##teamcity[jacocoReport dataPath='<path to jacoco.exec file>']
因此,我修改了我的 build.gradle 文件,将以下行添加到 jacocoTestReport
部分:
if (project.hasProperty("teamcity")) {
println '##teamcity[jacocoReport dataPath=\'app/build/jacoco/testDebug.exec\' includes=\'com.mynamespace.myproject.*\' excludes=\'**/R.class **/R$*.class **/*$ViewInjector*.* **/BuildConfig.* **/Manifest*.*\']'
}
在那之后,完整的jacocoTestReport
是:
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
classDirectories = fileTree(
dir: '../app/build/intermediates/classes/debug',
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*']
)
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files('../app/build/jacoco/testDebug.exec')
if (project.hasProperty("teamcity")) {
println '##teamcity[jacocoReport dataPath=\'app/build/jacoco/testDebug.exec\' includes=\'com.mynamespace.myproject.*\' excludes=\'**/R.class **/R$*.class **/*$ViewInjector*.* **/BuildConfig.* **/Manifest*.*\']'
}
reports {
xml.enabled = true
html.enabled = true
}
}
Teamcity 开始报告 CodeCoverage 如下: