简体   繁体   English

Android检测的单元测试将无法在一个物理设备上运行

[英]Android instrumented unit test will not run on one physical device

I have one device that throws an exception when I try to run unit tests on a project recently converted to use the androidX support libraries. 当我尝试在最近转换为使用androidX支持库的项目上运行单元测试时,有一个设备引发异常。 The tests have run on emulators and other physical devices. 测试已在模拟器和其他物理设备上运行。

The device it will not run on is a Pixel 2 running 9. 它将无法运行的设备是运行9的Pixel 2。

App crashes with this exception: 应用程序因以下异常而崩溃:

AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: PID: 7050
AndroidRuntime: java.lang.IllegalStateException: Call to getContentProviderExternal for: android_support_test_services.speak_easy returns null!
AndroidRuntime:     at androidx.test.services.speakeasy.client.ToolConnection$ToolConnectionPostIcs.doCall(ToolConnection.java:155)
AndroidRuntime:     at androidx.test.services.speakeasy.client.ToolConnection.publish(ToolConnection.java:93)
AndroidRuntime:     at androidx.test.services.speakeasy.client.ToolConnection.publish(ToolConnection.java:83)
AndroidRuntime:     at androidx.test.services.shellexecutor.BlockingPublish.getResult(BlockingPublish.java:79)
AndroidRuntime:     at androidx.test.services.shellexecutor.ShellCommandExecutorServer.start(ShellCommandExecutorServer.java:80)
AndroidRuntime:     at androidx.test.services.shellexecutor.ShellMain.main(ShellMain.java:45)
AndroidRuntime:     at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
AndroidRuntime:     at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)
AndroidRuntime: Error reporting crash
AndroidRuntime: java.lang.RuntimeException: Bad file descriptor
AndroidRuntime:     at android.os.BinderProxy.transactNative(Native Method)
AndroidRuntime:     at android.os.BinderProxy.transact(Binder.java:1127)
AndroidRuntime:     at android.app.IActivityManager$Stub$Proxy.handleApplicationCrash(IActivityManager.java:3711)
AndroidRuntime:     at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:143)
AndroidRuntime:     at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
AndroidRuntime:     at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
AndroidRuntime:     at java.lang.Thread.dispatchUncaughtException(Thread.java:1955)

Simplified Unit Test: 简化的单元测试:

import androidx.test.rule.ActivityTestRule
import org.junit.Assert
import org.junit.Rule
import org.junit.Test

class MyTest {

    @Rule
    var activityTestRule: ActivityTestRule<AuthAppActivity> = object : ActivityTestRule<AuthAppActivity>(AuthAppActivity::class.java, false, false) {
        override fun afterActivityLaunched() {
        }

        override fun beforeActivityLaunched() {
        }
    }

    @Test
    fun runTest() {

        Assert.assertTrue(true);   // low standards here
    }
}

And the relevant dependencies: 和相关的依赖项:

testImplementation('junit:junit:4.12') {
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testImplementation 'org.hamcrest:hamcrest-library:1.3'

androidTestImplementation "androidx.annotation:annotation:1.0.0"

androidTestImplementation "androidx.test:runner:1.1.0"
androidTestImplementation "androidx.test:rules:1.1.0"

androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'

androidTestImplementation "androidx.test.espresso:espresso-core:3.1.0"
androidTestImplementation "androidx.test.espresso:espresso-idling-resource:3.1.0"
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.1.0"
androidTestImplementation "androidx.test.espresso:espresso-web:3.1.0"
androidTestImplementation "androidx.test.espresso:espresso-intents:3.1.0"

The provider android_support_test_services.speak_easy is obviously missing from the device. 设备显然缺少提供程序android_support_test_services.speak_easy。 I ran the test on the working device and see that the same provider is used and found on that device. 我在正常运行的设备上进行了测试,发现在该设备上使用并找到了相同的提供程序。 I pulled up an older branch, prior to AndroidX, ran the a instrumented test from there and then switched back, the error was gone. 在AndroidX之前,我拉起了一个较旧的分支,从那里运行了测试测试,然后又切换回去,错误消失了。

Older version installed these versions: 旧版本安装了以下版本:

test-services-1.0.2.apk
orchestrator-1.0.2.apk

Newer androidx: 较新的androidx:

orchestrator-1.1.0-alpha3.apk
test-services-1.1.0-alpha3.apk

我终于意识到我使用了旧版本的Test Orchestrator 链接后终于解决了这个问题,尽管我将所有其他测试包都更新为androidx.test ,但我不小心依赖于旧的android.support.test版本,而不是androidx.test版本。 。测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将JVM单元测试作为Android的测试运行 - Run JVM unit test as an Android instrumented test 仪器化的Android单元测试和ProGuard - Instrumented Android Unit Test and ProGuard 如何在 Android Studio 中一键运行所有(单元和检测)测试 - how to run all (unit and instrumented) tests with one click in Android Studio 如何在物理设备上运行 android 仪器测试? - How to run android instrument test on physical device? 项目库上的Android Instrumented单元测试 - Android Instrumented unit test on project library AWS Device Farm - Android 仪器测试的权限 - AWS Device Farm - permissions for Android Instrumented test 如何在 Android 中使用单元测试或插桩测试来测试警报管理器 - How to test Alarm Manager using Unit Test or Instrumented Test in Android 在 App Center 中运行 Android JVM(未检测)单元测试 - Run Android JVM (not instrumented) unit tests in App Center 物理设备上的 Android 单元测试实际上是一回事吗? - Is Android unit testing on a physical device actually a thing? Android Espresso 测试在物理设备上失败(PerformException) - Android Espresso test failed on physical device (PerformException)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM