Hello,
I need help setting up JaCoCo to generate coverage report for manual tests of Android app (multimodule project). I´ve used AI for setup, but it did not bring any valid results. So far I was able to write task for generating report and run it without error, but it did not generate anything.
Here is what I do:
-
configure testCoverageEnabled true for each subproject by
subproject.afterEvaluate { if (subproject.plugins.hasPlugin('com.android.application') || subproject.plugins.hasPlugin('com.android.library')) { subproject.android.buildTypes.debug.testCoverageEnabled = true } }
I´ve tried manual configuration of some subprojects as well, did not get different result -
Created task for generating report:
apply plugin: ‘jacoco’ tasks.register(‘generateCombinedCoverageReport’, JacocoReport) { def coverageFile = file("D:\\Stažené\\coverage.ec") executionData.setFrom(files(coverageFile)) def modules = [ project(':app'), project(':qrScan'), ] def sourceDirs = [] def classDirs = [] modules.each { module -> sourceDirs += files('../app/src/main/java') classDirs += fileTree( dir: "${module.buildDir}/intermediates/javac/debug/compileDebugJavaWithJavac/classes", excludes: [ '**/BR.class', '**/androidx*', '**/dagger*', '**/hilt*', ]) } sourceDirectories.setFrom(files(sourceDirs)) classDirectories.setFrom(files(classDirs)) reports { xml.required.set(false) html.required.set(true) html.outputLocation.file("D:\\Stažené\\report.html") } doFirst { println "Coverage file exists: ${coverageFile.exists()}" println "Included modules: ${modules*.name}" println "Source dirs: ${sourceDirs}" println "Class dirs: ${classDirs}" new File("$buildDir/intermediates/javac/debug/compileDebugJavaWithJavac/classes").eachFileRecurse { file -> if (file.name.contains('$$')) { file.renameTo(file.path.replace('$$', '$')) } } }I´ve tried also with different report locations (even default ones)
-
Then I run “./gradlew clean assembleDebug”
-
Then I install the app using “adb install -r .\app\build\outputs\apk\debug\debug.apk”
-
Then I do the manual tests targeting mainly code from the modules explicitly mentioned in task that generates the report
-
Then I use “adb shell am instrument -w -e coverage true -e coverageFile /data/data/com.nn.myapp.debug/files/coverage.ec com.nn.myapp.debug/androidx.test.runner.AndroidJUnitRunner” which generates .ec report. This report has usually about 300-400kb (depending on how much of manual testing I do)
-
I download the report to the path specified in task for generating report
-
I launch the task for generating report, but I get no report
I was also trying to specify test class in point 6 to “run” empty test method, but it did not work. “am instrument” said that there is no such class. According to AI it does not matter because coverage data are supposed to be gathered since app starts.
Please help me figure out whats the problem and get me my report. Thanks!