簡體   English   中英

Android檢測的單元測試將無法在一個物理設備上運行

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

當我嘗試在最近轉換為使用androidX支持庫的項目上運行單元測試時,有一個設備引發異常。 測試已在模擬器和其他物理設備上運行。

它將無法運行的設備是運行9的Pixel 2。

應用程序因以下異常而崩潰:

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)

簡化的單元測試:

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
    }
}

和相關的依賴項:

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"

設備顯然缺少提供程序android_support_test_services.speak_easy。 我在正常運行的設備上進行了測試,發現在該設備上使用並找到了相同的提供程序。 在AndroidX之前,我拉起了一個較舊的分支,從那里運行了測試測試,然后又切換回去,錯誤消失了。

舊版本安裝了以下版本:

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

較新的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM