【错误记录】Android Studio 中生成测试覆盖率报告出错 ( ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED )
2023-09-14 09:07:28 时间
一、报错信息
在 Android Studio 工程中 , 启用了 " android # buildTypes # debug " 中的 testCoverageEnabled 配置 , 设置为 true , 目的是为了生成测试覆盖率报告 ;
kim.hsl.svg.ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED
org.junit.ComparisonFailure: expected:<kim.hsl.svg[]> but was:<kim.hsl.svg[.tom.jerry]>
at org.junit.Assert.assertEquals(Assert.java:115)
> Task :app:connectedDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
build.gradle 配置文件如下 :
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "kim.hsl.svg"
minSdkVersion 18
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// 生成 PNG 图片配置
//generatedDensities = ['hdpi', 'mdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi']
// 使用 com.android.support:appcompat 支持库配置
vectorDrawables.useSupportLibrary = true
// 国际化资源配置, 只打包默认资源与英文资源
resConfigs 'en'
ndk {
abiFilters "armeabi-v7a" , "arm64-v8a", "x86", "x86_64"
}
buildConfigField("boolean", "isGooglePlay", "true")
buildConfigField("String", "market", '"GooglePlay"')
applicationIdSuffix ".tom"
}
signingConfigs {
mySigningConfig {
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
release {
// 是否开启优化混淆
minifyEnabled true
// 是否启用资源压缩 , 未使用的资源会被优化
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".jerry"
signingConfig signingConfigs.mySigningConfig
testCoverageEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
// 矢量图支持库 , 支持 5.0 以下版本手机使用矢量图 , 这个是创建应用时自带的配置
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
二、解决方案
分析错误提示 :
kim.hsl.svg.ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED
org.junit.ComparisonFailure: expected:<kim.hsl.svg[]> but was:<kim.hsl.svg[.tom.jerry]>
at org.junit.Assert.assertEquals(Assert.java:115)
期望得到包名 kim.hsl.svg[]
, 但是目前包名为 kim.hsl.svg[.tom.jerry]
,
当前在 " android # defaultConfig " 中设置了 applicationIdSuffix ".tom"
包名后缀 ,
在 " android # buildTypes # debug " 中设置了 applicationIdSuffix ".jerry"
包名后缀 ,
导致最终生成 测试覆盖率报告 出现问题 ;
屏蔽这两个后缀即可正确生成 " 测试覆盖率报告 " ;
再次执行
gradlew :app:createDebugCoverageReport
命令 , 生成 " 测试覆盖率报告 " 成功 ,
生成路径为 " app\build\reports\coverage\debug " ;
打开 " app\build\reports\coverage\debug\index.html " 页面 , 内容如下 :
相关文章
- Android 错误:IllegalStateException: Can not perform this action after onSaveInstanceState
- Android Studio错误提示:Gradle project sync failed. Basic functionality (eg. editing, debugging) will not work properly
- [Android Pro] 控制硬加速 hardwareAccelerated 在3.0才有的
- android 关于InputDispatcher出现Consumer错误的解决办法
- Android studio怎么导入Recycler VIew
- android 减少图片出现oom错误
- Android错误:Re-installation failed due to different application signatures
- Android错误之error loading /system/media/audio/ui/Effect_Tick.ogg
- Android glide设置占位符和错误符的颜色背景
- Android kotlin 系列讲解(进阶篇) 更强大的滚动控件 - RecyclerView
- Android 9.0 屏蔽Launcher3桌面app图标的长按功能
- Android入门级编译错误汇总
- 【错误记录】Android Studio 集成 ARoute 编译报错 ( 兼容 support 库和 androidx 库 | add ‘tools:replace=“android:appCo )
- 【Android Gradle 插件】Android Library 依赖库混淆配置 ( ProductFlavor#consumerProguardFiles 配置 | 依赖库混淆配置 )
- 【错误记录】Android Studio 编译报错 ( AAPT: error: failed to read PNG signature: file does not start with PN )
- 【错误记录】Android Studio 中编写 Gradle 编译脚本时没有 Groovy 代码提示 ( Cannot find declaration to go to )
- 【错误记录】p7zip 交叉编译 Android 版本 NDK 报错 ( error: case value evaluates to -2 , which cannot be narrowed )
- Android记住password后自己主动登录
- Flutter Android app 修改启动背景颜色和logo——筑梦之路