【发布时间】:2017-08-22 23:25:43
【问题描述】:
我正在关注这两个链接 1 和 2 以获取 espresso 测试报告,但在运行 ./gradlew createDebugCoverageReport 时出现错误。错误将显示在下面给出的图像中。请帮助我,我无法为 espresso 和 ui 自动化测试用例生成报告。现在尝试使用jacoco,但找不到任何解决方案。
Build.Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.project"
minSdkVersion 18
targetSdkVersion 24
versionCode 27
versionName "1.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testCoverageEnabled true
}
debug{
testCoverageEnabled true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.github.barteksc:android-pdf-viewer:2.0.3'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-crash:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-annotations:24.2.0'
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0'
androidTestCompile 'com.android.support:support-annotations:24.2.1'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-v7'
exclude group: 'com.android.support', module: 'design'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile "com.android.support.test.espresso:espresso-intents:2.2.2"
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'jacoco'
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
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: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/code-coverage/connected/*coverage.ec"
])
}
【问题讨论】:
-
几个问题可以帮助你:1)你使用什么版本的Android Studio来创建项目? 2)你可以发布你的 build.gradle 文件吗? 3)您的目标是从 Android Studio 还是从 IDE 外部运行它?另外,我建议通过此答案中的建议步骤:stackoverflow.com/a/25525390/3195307
-
1)。 Android Studio 最新版本 2.3 2)。是的,请检查我的编辑,我已经发布了我的 build.gradle 3)我想通过 android studio 生成我的报告,当我并排运行代码时,应该生成报告。好的,我会检查你提供的链接,并很快报告你
-
没有从您提供的链接中找到任何帮助
-
很遗憾听到这个消息,至少我们检查了其他潜在问题。我相信这是因为您在目标项目目录之外执行 gradle 。尝试将目录更改为项目的根目录,然后使用特定参数调用 gradlew.bat,例如: C:\Users\Aman\YourProjectRoot\gradlew.bat :app:createDebugCoverageReport 我在 Mac 上,但是当我执行类似的 gradle wrapper 命令,覆盖率报告在 ./app/reports/androidTests/connected 下生成为 HTML 文件
-
嘿,它有效。问题是 genymotion,因为没有设备连接到运行应用程序。谢谢保罗
标签: android android-gradle-plugin ui-automation android-espresso