android - 无法使用 com.android.test 模块插件运行 android espresso 测试
问题描述
我正在尝试分离一些 espresso 测试,使用com.android.test
将作为功能测试运行的测试插件,因此不需要模拟,我只想使用 Espresso 和 uiautomator 进行一些 UI 自动化。
我已经用最简单的测试用例配置了测试项目,只是为了检查我的主要活动是否已启动:
@RunWith(AndroidJUnit4::class)
@LargeTest
class LoginTest {
@Rule
@JvmField
var mActivityTestRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
@Test
fun test() {
Thread.sleep(15 * 1000)
}
}
但是在活动启动后它会崩溃,并给出以下错误:
E/MonitoringInstr: Exception encountered by: com.****.****ui.main.MainActivity@9c9faca. Dumping thread state to outputs and pining for the fjords.
android.content.res.Resources$NotFoundException: Drawable com.****.****/change_chart_icons_size with resource ID #0x7f070059
这很奇怪,原因有两个:1)主应用程序找不到资源ID,它在那里(应用程序在活动测试规则之外正常运行)。并且 2) 该资源不是可绘制资源,而是维度资源。所以没有意义...
这是我的build.gradle
文件:
apply plugin: 'com.android.test'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion versions.target_sdk
defaultConfig {
minSdkVersion versions.min_sdk
targetSdkVersion versions.target_sdk
testApplicationId 'com.****.****.test'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
targetProjectPath ':mobile'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
implementation "com.google.dagger:dagger:$versions.dagger_version"
implementation "com.google.dagger:dagger-android:$versions.dagger_version"
implementation "com.google.dagger:dagger-android-support:$versions.dagger_version"
implementation "com.android.support:support-v4:$versions.support"
implementation "com.android.support:appcompat-v7:$versions.support"
implementation "com.android.support:percent:$versions.support"
implementation "com.android.support:design:$versions.support"
implementation "com.android.support:cardview-v7:$versions.support"
implementation "com.android.support:recyclerview-v7:$versions.support"
implementation 'com.android.support.test:runner:1.0.2'
implementation 'com.android.support.test:rules:1.0.2'
implementation "org.mockito:mockito-android:$versions.mockito"
implementation "com.nhaarman:mockito-kotlin:1.1.0"
implementation('com.android.support.test.espresso:espresso-core:3.0.2')
implementation('com.android.support.test.espresso:espresso-intents:3.0.2')
implementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
implementation 'xmlwise:xmlwise:1.2.11'
}
我没有主意了,我不知道是不是因为我用匕首弄坏了;因为我已经放弃了com.android.support
在新项目中实现模块测试的库的问题。
解决方案
推荐阅读
- asp.net-ajax - 在 Google Map 中渲染大量标记和折线的性能问题
- sql - 从两个日期列生成日期范围
- gis - 如何从 enu 向量中获取方位角和仰角
- mysql - MYSQL 选择 COLUMN(CONDITION) WHERE 条件
- python - 可以用 python 捕获 ffmpeg 错误吗?
- javascript - 检测正则表达式之间有或没有空格的特定字符串
- modelica - 变量在“when sample()”语句中自动重置为零
- java - Caesar Cipher 在空格后不读取单词,无法弄清楚原因
- mysql - 我想从 MySQL 表中删除重复的行
- azure-data-lake - 如何使用 Azure API 管理从 Azure Data Lake Rest API 获取响应?