运行Android测试时没有JSBridge错误

时间:2016-03-10 21:42:54

标签: android-testing

在运行androidTests时间歇性地,我收到一条消息'Test running startedFinish Empty test suite'。以及下面给出的堆栈跟踪。

我通过Wi-Fi使用ADB运行测试,因为我的设备使用USB连接到另一台设备。当我注意到这个异常时,我确保设备仍然连接。为了清楚起见,我的应用程序是一个原生应用程序,没有webview。

I/MonitoringInstrumentation: No JSBridge.
        java.lang.ClassNotFoundException: android.support.test.espresso.web.bridge.JavaScriptBridge
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:251)
        at java.lang.Class.forName(Class.java:216)
        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621)
        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90)
        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232)
        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5602)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoClassDefFoundError: android/support/test/espresso/web/bridge/JavaScriptBridge
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:251) 
        at java.lang.Class.forName(Class.java:216) 
        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621) 
        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90) 
        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232) 
        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747) 
        at android.os.Handler.handleCallback(Handler.java:733) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:146) 
        at android.app.ActivityThread.main(ActivityThread.java:5602) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.test.espresso.web.bridge.JavaScriptBridge" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/my.app.unittest.testapp.test-18.apk", zip file "/data/app/my.app.unittest.testapp-3.apk"],nativeLibraryDirectories=[/data/app-lib/my.app.unittest.testapp.test-18, /data/app-lib/my.app.unittest.testapp-3, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:251) 
        at java.lang.Class.forName(Class.java:216) 
        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621) 
        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90) 
        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232) 
        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747) 
        at android.os.Handler.handleCallback(Handler.java:733) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:146) 
        at android.app.ActivityThread.main(ActivityThread.java:5602) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
        at dalvik.system.NativeStart.main(Native Method) 
        03-10 13:24:27.993 32423-32437/my.app.unittest.testapp I/MonitoringInstrumentation: waitForActivitiesToComplete() took: 0ms
        03-10 13:24:27.993 32423-32423/my.app.unittest.testapp I/MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: 0
        03-10 13:24:28.213 580-591/? I/ActivityManager: Killing 32423:my.app.unittest.testapp/u0a233 (adj 0): stop my.app.unittest.testapp

这是我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "my.app.unittest.testapp"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support:support-annotations:23.1.1'

    androidTestCompile 'com.android.support.test:runner:0.4'
    // Set this dependency to use JUnit 4 rules
    androidTestCompile 'com.android.support.test:rules:0.4'
    // Set this dependency to build and run Espresso tests
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    // UiAutomator Testing
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
    androidTestCompile 'org.hamcrest:hamcrest-integration:1.3'

    compile project(':android-sdk')
}

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,试着更新测试库。

androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

检查ATSL发布说明下面的错误修复

https://google.github.io/android-testing-support-library/downloads/release-notes/

Espresso 2.2.2 Bug修复 - 删除了没有JSBridge的堆栈跟踪转储