使用Espresso运行检测测试:预验证类中的类ref解析为意外实现

joo*_*nli 9 instrumentation android android-espresso

我正在使用google-espresso测试平台Kitkat上的系统应用程序联系人.我的测试项目位于#android-dir#/ cts/tests/tests/contactTest.

这是.mk:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

# don't include this package in any target
LOCAL_MODULE_TAGS := optional
# and when built explicitly put it in the data partition
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)

LOCAL_JAVA_LIBRARIES := android.test.runner

LOCAL_STATIC_JAVA_LIBRARIES += librarycontacts

LOCAL_CERTIFICATE := shared

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := contactsTest

LOCAL_INSTRUMENTATION_FOR := Contacts

include $(BUILD_CTS_PACKAGE)

##################################################
include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += librarycontacts:libs/espresso-1.0-SNAPSHOT-bundled.jar

include $(BUILD_MULTI_PREBUILT)
Run Code Online (Sandbox Code Playgroud)

这是Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.contacts.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="19" />

    <instrumentation
        android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
        android:targetPackage="com.android.contacts" />

    <application>
        <uses-library android:name="android.test.runner" />
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

这是命令:

> $ mmm cts/tests/tests/contactsTest/
> $ adb install -r out/target/product/generic/data/app/contactsTest.apk
> $ adb shell am instrument -w -r com.android.contacts.test/com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner
Run Code Online (Sandbox Code Playgroud)

然后我收到了这个错误:

INSTRUMENTATION_RESULT: longMsg=java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
Run Code Online (Sandbox Code Playgroud)

当我用eclipse编译和运行它时,一切都好.它只是在这里失败了,我已经尝试了两个espresso-dependenciesespresso-standalone遵循指南,一切都行不通.

这个问题真让我搞砸了.我是新来的,任何回复都表示赞赏.谢谢.

ano*_*non 6

我在Espresso 2中遇到了这个问题,并最终发现依赖问题与支持库有关.我将以下内容添加configurations到顶层build.gradle以解决此问题.

configurations {
    androidTestCompile.exclude group: 'com.android.support'
    androidTestCompile.exclude module: 'support-v4'
}

dependencies {
    compile 'com.android.support:support-v4:21.+'
    // more dependencies

    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}
Run Code Online (Sandbox Code Playgroud)


Pau*_*ris 0

这是一个恼人的错误,但相对容易修复。你得到它的原因是因为你在同一个进程中有同一个类的多个版本,通常在测试项目中,这是因为你的测试应用程序中有一个库存在于你的真实应用程序中,或者你正在你的应用程序中编译测试 apk,当测试运行时它就会崩溃。

要解决此问题,您所要做的就是将测试应用程序中的所有内容更改为提供的依赖项。