一、Gradle配置信息

apply plugin: "jacoco"
jacoco {
    toolVersion = "0.8.4"
    reportsDir = file("$buildDir/customJacocoReportDir")
}
jacocoTestReport {
    reports {
        html.enabled true
        csv.enabled false
        xml.enabled true
        xml.destination file("$buildDir/jacocoXml.xml")
        html.destination file("$buildDir/jacocoHtml")
    }
    afterEvaluate {
        getClassDirectories().setFrom(
                classDirectories.files.collect {
                    fileTree(dir: it,
                            exclude: ['需要排除的路径, it路径是classes'])
                }
        )
    }
}
test {
    jacoco {
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
        classDumpDir = file("$buildDir/jacoco/classpathdumps")
    }

二、生成报告

  1. 点击执行test
  2. 点击执行jacocoTestReport
  3. 查看生成报告

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐