LoginSignup
19
14

More than 5 years have passed since last update.

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

Last updated at Posted at 2015-03-11

前提

  • 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

19
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
14