【发布时间】:2018-01-23 15:28:51
【问题描述】:
我正在尝试使用 jacoco 设置测试覆盖率,但到目前为止我没有成功。
在我的 build.gradle 中我添加了:
apply plugin: 'jacoco'
(...)
buildTypes {
debug {
testCoverageEnabled true
}
(...)
task jacocoTestReport(type: JacocoReport, dependsOn: "test<MyFlavor>DebugUnitTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = []
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: project.projectDir, includes:
['**/*.exec' , '**/*.ec'])
}
然后我使用以下代码运行 JaCoCo 测试报告:
./gradlew clean create<MyFlavor>DebugCoverageReport jacocoTestReport
我看到单元测试运行成功,但是当我打开测试报告时,位于:
<project>/build/reports/jacoco/jacocoTestReport/html/index.html
报告似乎是空的,因为覆盖率报告为 N/A,甚至项目包都没有显示。
此外,如果我尝试在
处打开覆盖率文件<project>/build/jacoco/test<MyFlavor>DebugUnitTest.exec
使用 Android Studio,所有类都报告 0.0% 的覆盖率。
我正在使用 gradle 3.0.1
我做错了什么? 这和口味的使用有关系吗?
【问题讨论】:
-
请显示 gradle 构建输出(仅限 Jacoco 详细信息)。