LoginSignup
8
7

More than 5 years have passed since last update.

jacocoを使ってカバレッジを取得するGradleタスクを作る

Posted at

Android Studioでライブラリプロジェクトのカバレッジを測定した時のメモです。

カバレッジを取りたいモジュールのbuild.gradleに以下を追加して、Run>Edit ConfigurationsからGradleタスクを登録しました。JsonPullParserを利用しているので、自動的に生成される*Genを除外するようにしました。


apply plugin: 'jacoco'

// カバレッジ測定タスク
task jacoco(type: JacocoReport, dependsOn: "testDebug") {
    reports {
        // CIツール上で実行する場合
//        xml.enabled = true
//        html.enabled = false
//        xml {
//            destination "${project.rootDir}/build/reports/jacoco/${project.name}/jacoco_report.xml"
//        }
        // AndroidStudioでタスクを単体実行する場合
        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',
                       '**/*Gen.class',
            ])
    sourceDirectories = files('src/main/java')
    executionData = files('build/jacoco/testDebug.exec')
}

8
7
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
8
7