Help us understand the problem. What is going on with this article?

gradle + jacoco でカバレッジレポートを出力する

More than 5 years have passed since last update.

前提

  • Gradle 2.3
  • (Android Studio 1.1.0)

設定追加

  • srcが含まれるディレクトリの build.gradle に下記を追記
  • とりあえずhtmlで出力できればいいので、html.enabled = true を指定
  • jacoco の toolVersionここから選択
build.gradle
apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.7.4.201502262128"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

task jacoco(type: JacocoReport, dependsOn: "testDebug") {
    reports {
        xml.enabled = false
        html.enabled = true
        html {
            destination "${project.rootDir}/build/reports/jacoco/${project.name}"
        }
    }
    classDirectories = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R.class',
                       '**/R$*.class',
                       '**/BuildConfig.class',
            ])
    sourceDirectories = files('src/main/java')
    executionData = files('build/jacoco/testDebug.exec')
}

実行

  • 下記コマンドで、destinationに指定したパスに、レポートが出力される。
 ./gradlew jacoco  

スクリーンショット_2015-03-11_10_53_58.png

tanakaworld
A Software Engineer. Creator of proff.io
https://tanaka.world
mercari
フリマアプリ「メルカリ」を、グローバルで開発しています。
https://tech.mercari.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away