0
点赞
收藏
分享

微信扫一扫

【错误记录】Android Studio 中生成测试覆盖率报告出错 ( ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED )



文章目录

  • ​​一、报错信息​​
  • ​​二、解决方案​​

一、报错信息

在 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.

【错误记录】Android Studio 中生成测试覆盖率报告出错 ( ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED )_android studio

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

命令 , 生成 " 测试覆盖率报告 " 成功 ,

【错误记录】Android Studio 中生成测试覆盖率报告出错 ( ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED )_gradle_02

生成路径为 " app\build\reports\coverage\debug " ;

【错误记录】Android Studio 中生成测试覆盖率报告出错 ( ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED )_groovy_03

打开 " app\build\reports\coverage\debug\index.html " 页面 , 内容如下 :

【错误记录】Android Studio 中生成测试覆盖率报告出错 ( ExampleInstrumentedTest > useAppContext[Pixel 2 - 9] FAILED )_groovy_04



举报

相关推荐

0 条评论