android - 如何使用模块和动态功能运行 UI 测试
问题描述
我目前正在玩动态功能。我无法运行任何 UI 测试。
我的应用程序有三个模块,如图所示:
- app - 常用模块
- dynamicFeatureA - 动态特征模块。它必须取决于app。这是实现动态功能时的要求
- shared - 一个包含一些共享逻辑和 3rd 方库的模块。我所有的测试/模拟库也在这里
在下面,您将找到每个模块的build.gradle文件。
应用程序
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
android {
compileSdkVersion 29
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.test.test"
minSdkVersion 26
targetSdkVersion 29
versionCode 7
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debuggable = false
}
}
flavorDimensions "environment"
productFlavors {
dev {
dimension "environment"
applicationIdSuffix ".dev"
}
prod {
dimension "environment"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
dynamicFeatures = [':dynamicFeatureA']
}
dependencies {
implementation project(':shared')
// Firebase
implementation platform('com.google.firebase:firebase-bom:25.12.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-auth-ktx'
api 'com.google.android.play:core:1.9.0'
}
共享
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 29
buildToolsVersion "30.0.3"
defaultConfig {
minSdkVersion 26
targetSdkVersion 29
versionCode 7
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
// Retrofit + OkHttp
api 'com.squareup.retrofit2:retrofit:2.6.2'
api 'com.squareup.retrofit2:converter-gson:2.1.0'
api 'com.squareup.okhttp3:logging-interceptor:4.2.1'
// Tests
api("junit:junit:4.13.1")
api 'androidx.test.ext:junit:1.1.2'
api 'androidx.test.espresso:espresso-core:3.3.0'
api "androidx.arch.core:core-testing:2.1.0"
api "io.mockk:mockk:1.10.4"
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
api "io.mockk:mockk-android:1.10.4"
api 'com.squareup.okhttp3:mockwebserver:4.2.2'
api 'androidx.test.uiautomator:uiautomator:2.2.0'
api 'androidx.test.ext:junit:1.1.2'
api 'androidx.test:runner:1.3.0'
api 'androidx.test:rules:1.3.0'
api 'androidx.test:core:1.3.0'
api 'androidx.test.ext:truth:1.3.0'
// Kotlin
api "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
api 'androidx.core:core-ktx:1.3.2'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4'
api 'androidx.appcompat:appcompat:1.2.0'
api 'com.google.android.material:material:1.2.1'
api "androidx.constraintlayout:constraintlayout:2.0.4"
}
动态特征A
plugins {
id 'com.android.dynamic-feature'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 29
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.test.test"
minSdkVersion 26
targetSdkVersion 29
versionCode 7
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "environment"
productFlavors {
dev {
dimension "environment"
applicationIdSuffix ".dev"
}
prod {
dimension "environment"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation project(":app")
implementation project(":shared")
}
尝试运行我的 UI 测试时,出现以下错误
Android resource linking failed
/.gradle/caches/transforms-2/files-2.1/d3cf80163c3f5e54a1f3dc792b3bfaac/jetified-core-1.9.0/AndroidManifest.xml:13:5-226: AAPT: error: resource style/Theme.PlayCore.Transparent (aka com.test.test.dev.test:style/Theme.PlayCore.Transparent) not found.
/.gradle/caches/transforms-2/files-2.1/2bbe030940076efec6cce94c1a3439fe/jetified-play-services-basement-17.0.0/AndroidManifest.xml:23:9-25:69: AAPT: error: resource integer/google_play_services_version (aka com.test.test.dev.test:integer/google_play_services_version) not found.
解决方案
推荐阅读
- c# - 使用 Moq 的单元测试 ac# 方法
- c# - 在c#中使用access数据库中的数据网格视图删除一行
- html - 如何在 HTML5 音频上添加循环?
- python - flask+apache+mod_wsgi 上的 cx_oracle 持久连接
- flutter - 当我们只有 .apk 文件时,如何检查来自 Flutter 移动应用程序的元素。(我们没有开发人员用来构建 .apk 的键值对)
- python - KeyConditionExpression 不在我的桌子上工作
- react-native - 如何根据 react-native 中的数据按价格对平面列表进行排序?
- linux - 在 CentOS 8 中从 pgdg 存储库安装 postgresql12-server 后找不到 pg_ctl
- javascript - 如何从#printable 部分删除一些项目。?
- mysql - 是否可以在 MySQL 中按多列(OR 语句)分组?