运行 Android 测试时没有 JSBridge 错误

问题描述 投票:0回答:2

运行 androidTests 时,我间歇性地收到一条消息“测试运行已开始完成空测试套件”。下面给出了发生这种情况时的堆栈跟踪。

当我的设备使用 USB 连接到另一个设备时,我使用 ADB 通过 Wi-Fi 运行测试。当我注意到这个异常时,我确保设备仍然处于连接状态。需要明确的是,我的应用程序是本机应用程序,没有网络视图。

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')
}
android-testing
2个回答
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/

浓缩咖啡2.2.2 Bug修复 - 删除了关于没有 JSBridge 的堆栈跟踪转储


0
投票

在我的例子中,当方法参数的数量不正确时(例如:android中的方法有3个参数,但在webview中调用它有5个参数)或者它们的类型不正确,就会发生错误。

© www.soinside.com 2019 - 2024. All rights reserved.