目前,我在使用connectedAndroidTest
生成仪器测试覆盖率和艾玛报告方面遇到了一个奇怪的问题。当我运行./gradlew connectedAndroidTest
时,它有时工作,生成报告,有时不工作。
当我通过adb shell am instrument
运行时,它总是工作的,但问题是我需要获得.ec
文件来自动与单元测试报告统一。我没有从第二次审判中改变任何东西。
输出:
MacBook-Pro:test-android dimas$ ./gradlew connectedAndroidTest
> Configure project :app
OneSignal Warning: Could not get AGP plugin version
> Task :app:kaptDebugAndroidTestKotlin
Annotation processors discovery from compile classpath is deprecated.
Set 'kapt.includeCompileClasspath = false' to disable discovery.
Run the build with '--info' for more details.
> Task :app:createDebugAndroidTestCoverageReport FAILED
> Task :app:connectedDebugAndroidTest
Starting 8 tests on Pixel_2_API_28(AVD) - 9
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:createDebugAndroidTestCoverageReport'.
> java.io.IOException: No coverage data to process in directories [/Users/.../app/build/outputs/code_coverage/debugAndroidTest/connected]
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1m 7s
61 actionable tasks: 13 executed, 48 up-to-date
MacBook-Pro:test-android dimas$ ./gradlew connectedAndroidTest
> Configure project :app
OneSignal Warning: Could not get AGP plugin version
> Task :app:connectedDebugAndroidTest
Starting 8 tests on Pixel_2_API_28(AVD) - 9
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 56s
61 actionable tasks: 2 executed, 59 up-to-date
这些是我的等级DSL设置,用于:
安卓相关
defaultConfig {
...
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
...
}
buildTypes {
all {
multiDexEnabled = true
...
}
getByName("debug") {
isDebuggable = true
isMinifyEnabled = false
isTestCoverageEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
...
}
...
}
Jacoco
/* Jacoco & Tests Related tasks */
jacoco {
toolVersion = "0.8.5"
}
测试
testOptions {
animationsDisabled = true
unitTests.apply {
isReturnDefaultValues = true
isIncludeAndroidResources = true
}
}
val sharedTestDir = "src/sharedTest/java"
sourceSets.getByName("test") {
java.srcDir(sharedTestDir)
}
sourceSets.getByName("androidTest") {
java.srcDir(sharedTestDir)
}
有人知道如何使它正常工作吗?看来,app:createDebugAndroidTestCoverageReport
内部任务在实际进行测试之前由gradle执行。
发布于 2020-07-28 19:49:30
将Gradle降级为4.0.0,将Gradle包装降为6.1.1,这对我来说是件好事。
https://stackoverflow.com/questions/62545729
复制相似问题