如何从代码覆盖率报告中排除包?

时间:2016-03-16 15:27:36

标签: android android-espresso jacoco

我目前正在使用createDebugAndroidTestCoverageReport来运行我的android检测测试并生成覆盖率报告。我遇到的唯一问题是有从Realm和Databinding生成的包,这些类也包含在我的覆盖报告中。如何配置jacoco以排除这些包?

2 个答案:

答案 0 :(得分:0)

test {
    jacoco {
        append = false
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
        classDumpFile = file("$buildDir/jacoco/classpathdumps")
        excludes = []
    }
}

Click here for more details on official Jacoco Gradle Plugin

答案 1 :(得分:0)

在定义 debugTree 时,您可以添加要排除的fileFilters。

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
 reports {
      xml.enabled = true
      html.enabled = true
 }
 def fileFilter = ['**/package/**']
 def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
}