运行 Android 测试时没有 JSBridge 错误

Ani*_*thy 5 android-testing

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

\n\n

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

\n\n
I/MonitoringInstrumentation: No JSBridge.\n        java.lang.ClassNotFoundException: android.support.test.espresso.web.bridge.JavaScriptBridge\n        at java.lang.Class.classForName(Native Method)\n        at java.lang.Class.forName(Class.java:251)\n        at java.lang.Class.forName(Class.java:216)\n        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621)\n        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90)\n        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232)\n        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747)\n        at android.os.Handler.handleCallback(Handler.java:733)\n        at android.os.Handler.dispatchMessage(Handler.java:95)\n        at android.os.Looper.loop(Looper.java:146)\n        at android.app.ActivityThread.main(ActivityThread.java:5602)\n        at java.lang.reflect.Method.invokeNative(Native Method)\n        at java.lang.reflect.Method.invoke(Method.java:515)\n        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)\n        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)\n        at dalvik.system.NativeStart.main(Native Method)\n     Caused by: java.lang.NoClassDefFoundError: android/support/test/espresso/web/bridge/JavaScriptBridge\n        at java.lang.Class.classForName(Native Method)\xc2\xa0\n        at java.lang.Class.forName(Class.java:251)\xc2\xa0\n        at java.lang.Class.forName(Class.java:216)\xc2\xa0\n        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621)\xc2\xa0\n        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90)\xc2\xa0\n        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232)\xc2\xa0\n        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747)\xc2\xa0\n        at android.os.Handler.handleCallback(Handler.java:733)\xc2\xa0\n        at android.os.Handler.dispatchMessage(Handler.java:95)\xc2\xa0\n        at android.os.Looper.loop(Looper.java:146)\xc2\xa0\n        at android.app.ActivityThread.main(ActivityThread.java:5602)\xc2\xa0\n        at java.lang.reflect.Method.invokeNative(Native Method)\xc2\xa0\n        at java.lang.reflect.Method.invoke(Method.java:515)\xc2\xa0\n        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)\xc2\xa0\n        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)\xc2\xa0\n        at dalvik.system.NativeStart.main(Native Method)\xc2\xa0\n     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]]\n        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)\n        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)\n        at java.lang.Class.classForName(Native Method)\xc2\xa0\n        at java.lang.Class.forName(Class.java:251)\xc2\xa0\n        at java.lang.Class.forName(Class.java:216)\xc2\xa0\n        at android.support.test.runner.MonitoringInstrumentation.tryLoadingJsBridge(MonitoringInstrumentation.java:621)\xc2\xa0\n        at android.support.test.runner.MonitoringInstrumentation.access$100(MonitoringInstrumentation.java:90)\xc2\xa0\n        at android.support.test.runner.MonitoringInstrumentation$4.run(MonitoringInstrumentation.java:232)\xc2\xa0\n        at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1747)\xc2\xa0\n        at android.os.Handler.handleCallback(Handler.java:733)\xc2\xa0\n        at android.os.Handler.dispatchMessage(Handler.java:95)\xc2\xa0\n        at android.os.Looper.loop(Looper.java:146)\xc2\xa0\n        at android.app.ActivityThread.main(ActivityThread.java:5602)\xc2\xa0\n        at java.lang.reflect.Method.invokeNative(Native Method)\xc2\xa0\n        at java.lang.reflect.Method.invoke(Method.java:515)\xc2\xa0\n        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)\xc2\xa0\n        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)\xc2\xa0\n        at dalvik.system.NativeStart.main(Native Method)\xc2\xa0\n        03-10 13:24:27.993 32423-32437/my.app.unittest.testapp I/MonitoringInstrumentation: waitForActivitiesToComplete() took: 0ms\n        03-10 13:24:27.993 32423-32423/my.app.unittest.testapp I/MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: 0\n        03-10 13:24:28.213 580-591/? I/ActivityManager: Killing 32423:my.app.unittest.testapp/u0a233 (adj 0): stop my.app.unittest.testapp\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的 build.gradle:

\n\n
apply plugin: \'com.android.application\'\n\nandroid {\n    compileSdkVersion 23\n    buildToolsVersion "23.0.2"\n\n    defaultConfig {\n        applicationId "my.app.unittest.testapp"\n        minSdkVersion 18\n        targetSdkVersion 23\n        versionCode 1\n        versionName "1.0"\n\n        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"\n        multiDexEnabled true\n    }\n    buildTypes {\n        release {\n            minifyEnabled false\n            proguardFiles getDefaultProguardFile(\'proguard-android.txt\'), \'proguard-rules.pro\'\n        }\n    }\n}\n\ndependencies {\n    compile fileTree(include: [\'*.jar\'], dir: \'libs\')\n    compile \'com.android.support:appcompat-v7:23.1.1\'\n    compile \'com.android.support:design:23.1.1\'\n    testCompile \'junit:junit:4.12\'\n    androidTestCompile \'com.android.support:support-annotations:23.1.1\'\n\n    androidTestCompile \'com.android.support.test:runner:0.4\'\n    // Set this dependency to use JUnit 4 rules\n    androidTestCompile \'com.android.support.test:rules:0.4\'\n    // Set this dependency to build and run Espresso tests\n    androidTestCompile \'com.android.support.test.espresso:espresso-core:2.2.1\'\n    // UiAutomator Testing\n    androidTestCompile \'com.android.support.test.uiautomator:uiautomator-v18:2.1.1\'\n    androidTestCompile \'org.hamcrest:hamcrest-integration:1.3\'\n\n    compile project(\':android-sdk\')\n}\n
Run Code Online (Sandbox Code Playgroud)\n

小智 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'
Run Code Online (Sandbox Code Playgroud)

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

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

Espresso 2.2.2 错误修复 - 删除了有关无 JSBridge 的堆栈跟踪转储