【发布时间】:2020-08-13 22:23:51
【问题描述】:
我正在使用 Jacoco 通过单元测试或仪器测试生成代码覆盖率的 HTML 报告。
我的android项目由几个模块组成:
- app(安卓应用);
- 自定义日历视图 (lib);
- iotcam (lib);
- qrcodereaderview (lib);
- singledateandtimepicker (lib)。
使用本教程:https://proandroiddev.com/unified-code-coverage-for-android-revisited-44789c9b722f 和本示例:https://github.com/rafaeltoledo/unified-code-coverage-android/blob/mixed-languages/jacoco.gradle 我编写了以下代码:
apply plugin: "jacoco"
jacoco
{
toolVersion = "0.8.5"
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
task executeUnitAndIntegrationTestsAndCreateReport(type: JacocoReport, dependsOn: ['testQaUnitAndIntegrationTestsDebugUnitTest', 'createQaUnitAndIntegrationTestsDebugCoverageReport']) {
reports
{
xml.enabled = true
html.enabled = true
html.destination file("${rootProject.buildDir}/coverage-report")
}
def javaClasses = []
def kotlinClasses = []
def javaSrc = []
def kotlinSrc = []
def execution = []
def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'androidx/**/*.*',
]
rootProject.subprojects.each { proj ->
println "current proj: $proj"
javaClasses << fileTree(dir: "$proj.buildDir/intermediates/javac/debug", excludes: fileFilter)
kotlinClasses << fileTree(dir: "$proj.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
javaSrc << "$proj.projectDir/src/main/java"
kotlinSrc << "$proj.projectDir/src/main/kotlin"
execution << fileTree(dir: proj.buildDir,
includes: ['**/*.exec', '**/*.ec'])
}
println "javaSrc: $javaSrc"
println "kotlinSrc: $kotlinSrc"
sourceDirectories.from = files([javaSrc, kotlinSrc])
classDirectories.from = files([javaClasses, kotlinClasses])
print execution
executionData.from = files(execution)
doLast() {
print "${reports.html.destination}/index.html"
}
根据日志,所有模块都考虑到了javaSrc 和kotlinSrc 变量中:
JavaSrc: [ C:\mypath\app/src/main/java, C:\mypath\custom-calendarview/src/main/java, C:\mypath\iotcam/src/main/java, C:\mypath\qrcodereaderview/src/main/java, C:\mypath\singledateandtimepicker/src/main/java ]
kotlinSrc: [ C:\mypath\app/src/main/kotlin, C:\mypath\custom-calendarview/src/main/kotlin, C:\mypath\iotcam/src/main/kotlin, C:\mypath\qrcodereaderview/src/main/kotlin, C:\mypath\singledateandtimepicker/src/main/kotlin ]
[ 目录 'C:\mypath\app\build', 目录 'C:\mypath\custom-calendarview\build', 目录'C:\mypath\iotcam\build', 目录 'C:\mypath\qrcodereaderview\build', 目录 'C:\mypath\singledateandtimepicker\build' ]
最后,代码覆盖率报告是正确生成的,但它包含所有子模块的包名,除了“app”一个:
注意,如果我点击“sessions”链接,我可以找到“app”模块的所有类。
如何将我的“应用”模块添加到此报告中?
感谢您的帮助!
【问题讨论】:
标签: java android kotlin code-coverage jacoco