Jacoco 代码覆盖率不包括我的应用程序模块在多模块 android 项目中
Jacoco code coverage does not include my app module in multi modules android project
我使用 Jacoco 是为了通过单元测试或仪器测试生成 HTML 代码覆盖率报告。
我的android项目由几个模块组成:
- app(android 应用程序);
- 自定义日历视图(库);
- iotcam(库);
- qrcodereaderview(库);
- 单一日期和时间选择器(库)。
使用本教程:https://proandroiddev.com/unified-code-coverage-for-android-revisited-44789c9b722f and this example : 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:\我的路径\app/src/main/java,
C:\我的路径\custom-calendarview/src/main/java,
C:\我的路径\iotcam/src/main/java,
C:\我的路径\qrcodereaderview/src/main/java,
C:\我的路径\singledateandtimepicker/src/main/java
]
kotlinSrc: [
C:\我的路径\app/src/main/kotlin,
C:\我的路径\custom-calendarview/src/main/kotlin,
C:\我的路径\iotcam/src/main/kotlin,
C:\我的路径\qrcodereaderview/src/main/kotlin,
C:\我的路径\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" link,我可以找到"app"模块的所有类。
如何将我的 "app" 模块添加到此报告中?
感谢您的帮助!
Jacoco 使用此插件完美运行:https://github.com/vanniktech/gradle-android-junit-jacoco-plugin
我使用 Jacoco 是为了通过单元测试或仪器测试生成 HTML 代码覆盖率报告。
我的android项目由几个模块组成:
- app(android 应用程序);
- 自定义日历视图(库);
- iotcam(库);
- qrcodereaderview(库);
- 单一日期和时间选择器(库)。
使用本教程:https://proandroiddev.com/unified-code-coverage-for-android-revisited-44789c9b722f and this example : 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:\我的路径\app/src/main/java, C:\我的路径\custom-calendarview/src/main/java, C:\我的路径\iotcam/src/main/java, C:\我的路径\qrcodereaderview/src/main/java, C:\我的路径\singledateandtimepicker/src/main/java ]
kotlinSrc: [ C:\我的路径\app/src/main/kotlin, C:\我的路径\custom-calendarview/src/main/kotlin, C:\我的路径\iotcam/src/main/kotlin, C:\我的路径\qrcodereaderview/src/main/kotlin, C:\我的路径\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" link,我可以找到"app"模块的所有类。
如何将我的 "app" 模块添加到此报告中?
感谢您的帮助!
Jacoco 使用此插件完美运行:https://github.com/vanniktech/gradle-android-junit-jacoco-plugin