我正在努力使用Espresso在Android上进行功能测试.我的应用程序是一个Multdex应用程序,所以我按照以下链接写的说明如下:(https://developer.android.com/tools/building/multidex.html).
我已经像这样配置了我的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.3.2'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'br.com.foo'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "br.com.foo"
minSdkVersion 15
targetSdkVersion 21
android.enforceUniquePackageName = false
multiDexEnabled true
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
testApplicationId "br.com.foo.test"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
} …Run Code Online (Sandbox Code Playgroud) 页面http://developer.android.com/tools/building/multidex.html#testing 建议
dependencies {
compile 'com.android.support:multidex:1.0.1'
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.1'
}
android {
defaultConfig {
multiDexEnabled true
testInstrumentationRunner "android.support.multidex.MultiDexTestRunner"
}
}
Run Code Online (Sandbox Code Playgroud)
但是在运行测试时会产生ClassNotFoundException.
API文档和dexdump显示有com.android.test.runner.MultiDexTestRunner.
所以如果我不相信文档而是指定
dependencies {
compile 'com.android.support:multidex:1.0.1'
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.1'
}
android {
defaultConfig {
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
}
Run Code Online (Sandbox Code Playgroud)
然后我明白了
com/company/myapp/MyApp; had used a different Landroid/support/multidex/MultiDexApplication; during pre-verification
...
IllegalAccessExceptionIllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
Run Code Online (Sandbox Code Playgroud)
我怀疑doc页面是错误的,正确的路径是com.android.test.runner.MultiDexTestRunner ...加上我还有其他一些问题.
请注意,multidex应用程序工作正常.不知何故,第二个MultiDexApplication包含在测试apk中.
问题:
MultiDexTestRunner的正确路径是哪条?为什么我在测试apk中获得第二个MultiDexApplication?