14

Since the release of 'com.android.tools.build:gradle:1.1.0' I'm moving most of my java test code from androidTest to the test folder because the JVM tests are a lot faster. But I cannot move all tests. I really need the device tests because of some ContentProvider stuff.

I've had 100% code coverage before I started migrating. When I'm currently running the jacoco code coverage I get 40% for the androidTest folder and 71% for the test folder. My code is 100% tested but I have no report proofing this.

Is there a way to combine both reports? I found JacocoMerge but couldn't get it to work.

Here is the output of the androidTest folder: build/outputs/reports/coverage/debug/index.html

And here the output of the test folder build/reports/jacoco/generateJacocoTestReports/html/index.html generated with this gradle task:

def coverageSourceDirs = [
        '../library/src/main/java'
]

task generateJacocoTestReports(type: JacocoReport, dependsOn: "test") {
    group = "Reporting"
    description = 'Generate Jacoco Robolectric unit test coverage reports'

    classDirectories = fileTree(
            dir: '../library/build/intermediates/classes/debug',
            excludes: ['**//*R.class',
                       '**//*R$*.class',
                       '***/*//*$ViewInjector*.*',
                       '**//*BuildConfig.*',
                       '**//*Manifest*.*']
            )
    sourceDirectories = files(coverageSourceDirs)
    additionalSourceDirs = files(coverageSourceDirs)
    executionData = files('../library/build/jacoco/testDebug.exec')
}
passsy
  • 5,162
  • 4
  • 39
  • 65
  • If you have found a solution for this I would appreciate any hints you can provide. Thanks. – Kevin Sep 02 '15 at 21:44

4 Answers4

6

Not sure if you still need this, but I recently published Gradle plugin which might help you with that: https://github.com/paveldudka/JacocoEverywhere

Pavel Dudka
  • 20,754
  • 7
  • 70
  • 83
1

There is also the gradle plugin https://github.com/palantir/gradle-jacoco-coverage that acording to docs can do the job, too.

I haven-t tried it for one submodul with two different test-parts but it works well for merging the testparts of to two submoduls.

See Gradle jacoco coverage report with more than one submodule(s)? for details

Community
  • 1
  • 1
k3b
  • 14,517
  • 7
  • 53
  • 85
1

JacocoMerge task can be used to merge 2 or more jacoco execution data.

Below task can be added to the root gradle file and on successful execution of this task, merged execution data can be found under root build directory. (build/jacoco/mergeJacocoReport.exec)

evaluationDependsOnChildren()
//Missing this might be a problem in fetching JacocoReport tasks from sub-modules.

 task mergeJacocoReport(type: org.gradle.testing.jacoco.tasks.JacocoMerge) {
    group "Jacoco Report"
    description "Merge Jacoco Code Coverage Report"

    def executionFiles = fileTree("$rootProject.rootDir", {
        includes = ['**/*.exec']
    })

    setExecutionData(executionFiles)

}

subprojects.each { $project ->
    def tasks = $project.tasks.withType(JacocoReport)

    if (tasks != null) {
        mergeJacocoReport.dependsOn << tasks
    }
}
Suryavel TR
  • 3,576
  • 1
  • 22
  • 25
0

In case you use Jenkins with the JaCoCo plugin you can just configure all jacoco.exec and emma.ec files in "Path to exec files" to have a combined coverage reported.

connectedAndroidTest will result in emma.ec files somewhere in "outputs" by default.