无法获取Espresso代码覆盖率报告,我是android studio的新手,并尝试了以下设置来生成报告。
请找到build.gradle设置:
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'realm-android'
apply plugin: 'jacoco'
buildTypes {
debug {
debuggable true
minifyEnabled false
multiDexEnabled true
testCoverageEnabled true
}
当我使用“ CreateDebugAndroidTestCoverage”运行记录的测试时,我得到以下报告:
我希望包含方法,行详细信息等的列:
请找到我期望的报告类型的屏幕截图:
答案 0 :(得分:0)
您需要通过在模块的 Gradle 文件(通常为 app/build.gradle
)中创建任务来为 jacoco 报告添加配置。在该任务中,您需要为 createDebugCoverageReport
属性添加 depnedsOn
。让我向您展示它的外观示例:
// Task declaration
task jacocoTestReport(type: JacocoReport) {
// Runs only after the dependencies are executed
dependsOn = ['testDebugUnitTest', 'createDebugCoverageReport']
// Export formats
reports {
xml.enabled = true
html.enabled = true
}
sourceDirectories.from = files(coverageSourceDirs)
classDirectories.from = fileTree(
dir: './build/intermediates/classes/debug',
excludes: ['**/R*.class'
])
// Inform Gradle where the files generated by test cases - are located
executionData.from = fileTree(dir: project.buildDir, includes: [
'jacoco/testDebugUnitTest.exec',
'outputs/code_coverage/debugAndroidTest/connected/*.ec'
])
}
现在,您可以使用覆盖率运行此任务,它将为您提供覆盖率。