【发布时间】:2017-03-30 09:39:07
【问题描述】:
我正在使用 espresso 和 ui 自动化测试用例,我的测试用例工作正常,但它们没有生成通过或失败的报告。为此,我搜索并找到了 jacoco,我尝试使用以下链接 https://docs.gradle.org/current/userguide/jacoco_plugin.html 根据这个链接我已经添加了插件、jacoco 版本和正在运行的应用程序,但仍然没有在调试文件夹中生成报告。尝试了很多但找不到任何解决方案。请帮助我找到解决方案。
应用级别的Build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.7.6.201602180812"
reportsDir = file("$buildDir/customJacocoReportDir")
}
def coverageSourceDirs = [
'src/main/java',
]
task jacocoTestReport(type: JacocoReport, dependsOn: "connectedDebugAndroidTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}
classDirectories = fileTree(
dir: './build/intermediates/classes/debug',
excludes: ['**/R*.class'
])
sourceDirectories = files(coverageSourceDirs)
executionData = files("$buildDir/jacoco/testDebug.exec")
// Bit hacky but fixes https://code.google.com/p/android/issues/detail?id=69174.
// We iterate through the compiled .class tree and rename $$ to $.
doFirst {
new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
}
}
}
}
【问题讨论】:
-
这个问题和我们的工作线程有什么不同吗? stackoverflow.com/questions/43094105/…
-
我已经解决了这个问题。因为我在 app 级别的 build.gradle 中添加了 jacoco,但是当我在项目级别添加 build.gradle 时。它可以工作。你能帮忙解决这个错误吗?很多小时。 stackoverflow.com/questions/43136553/…
标签: android ui-automation jacoco android-espresso