Skip to content

Instantly share code, notes, and snippets.

@wangjiegulu
Last active November 19, 2016 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wangjiegulu/76c668f75536fe7ddb4b18545bb369dc to your computer and use it in GitHub Desktop.
Save wangjiegulu/76c668f75536fe7ddb4b18545bb369dc to your computer and use it in GitHub Desktop.
Android_Jacoco_Unit_Test
apply plugin: 'jacoco'

buildTypes {
        debug {
            // ...
            // 打开该属性的话,在断点调试的时候会导致方法参数值丢失(看不到),所以在调试的时候要记得把它关掉
            testCoverageEnabled true
        }
}

jacoco {
    // http://www.eclemma.org/jacoco/
    toolVersion = "$global_jacocoToolVersion"
}

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

task jacocoTestReport(type:JacocoReport, dependsOn: "testDebugUnitTest") {
    group = "Reporting"

    description = "Generate Jacoco coverage reports"

//    classDirectories = fileTree(
//            dir: '../app/build/intermediates/classes/debug',
//            excludes: ['**/R.class',
//                       '**/R$*.class',
//                       '**/*$ViewInjector*.*',
//                       '**/BuildConfig.*',
//                       '**/Manifest*.*']
//    )

    classDirectories = fileTree(
            dir: '../app/build/intermediates/classes/debug',
            includes: ['**/*Presenter.class']
    )

    additionalSourceDirs = files(coverageSourceDirs)
    sourceDirectories = files(coverageSourceDirs)
    executionData = files('../app/build/jacoco/testDebugUnitTest.exec')

    reports {
        xml.enabled = true
        html.enabled = true
    }

}

// ==>
gradle clean testDebugUnitTest jacocoTestReport

// ==>
ProjectRoot\app\build\reports\jacoco\jacocoTestReport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment