Global code coverage in an Android multi-module project: merge code coverage reports (Unit & UI tests)

I have an android application consisting of 2 modules:

  • App - UI

  • Submodule - has most of the business logic

For each of them, I have a gradle task to check for code coverage:

  • Application: UI code coverage (espresso)

  • Submodule: unit test code coverage

As a requirement for the client, I need to combine these two reports to get a common / global coverage of the code .

Note. I am using Gradle version 3.0.0.

I tried several ways, but nobody works for me ...

The task of creating coverage in the application:

task createTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'lint', 'createUitestingAndroidTestCoverageReport']) { group = "Reporting" reports { xml.enabled = true html.enabled = true } def fileFilter = ['**/R.class', '**/BR.class', '**/R$*.class', '**/BR$*.class', '**/BuildConfig.*', '**/*databinding/**/*.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug/", excludes: fileFilter) def mainSrc = "${project.projectDir}/src/main/java" sourceDirectories = files([mainSrc]) classDirectories = files([debugTree]) executionData = files("${project.buildDir}/jacoco/testDebugUnitTest.exec") } 

The task for creating a report in the module:

 task createTestReport(type: JacocoReport, dependsOn: ['testUnitTestUnitTest']) { reports { html.enabled = true } def fileFilter = ['**/R.class', '**/BR.class', '**/R$*.class', '**/BR$*.class', '**/BuildConfig.*', '**/*databinding/**/*.*', '**/Manifest*.*', '**/*Test*.*', "**/services/**/model/**", 'android/**/*.*'] def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/unitTest", excludes: fileFilter) def mainSrc = "${project.projectDir}/src/main/java" def debugSrc = "${project.projectDir}/src/debug/java" sourceDirectories = files([mainSrc, debugSrc]) classDirectories = files([debugTree]) executionData = files("${buildDir}/jacoco/testUnitTestUnitTest.exec") } 

I have already tested several examples that use subprojects.sourceSets , but Gradle does not recognize the sourceSets parameter , you can check here


Another approach tried to almost replicate the module task, but mostly build.gradle

 task jacocoTestReport(type: JacocoReport) { reports { html.enabled = true } def fileFilter = ['**/R.class', '**/BR.class', '**/R$*.class', '**/BR$*.class', '**/BuildConfig.*', '**/*databinding/**/*.*', '**/Manifest*.*', '**/*Test*.*', "**/services/**/model/**", 'android/**/*.*'] def debugTree = fileTree(dir: "${project.projectDir}/module/build/intermediates/classes/unitTest", excludes: fileFilter) def mainSrc = "${project.projectDir}/module/src/main/java" def debugSrc = "${project.projectDir}/module/src/debug/java" sourceDirectories = files([mainSrc, debugSrc]) classDirectories = files([debugTree]) executionData = files("${project.projectDir}/module/build/jacoco/testUnitTestUnitTest.exec") } 

But the result is this: path may not be null or empty string. path='null' path may not be null or empty string. path='null'

Any help would be greatly appreciated

+5
source share

Source: https://habr.com/ru/post/1273474/


All Articles