Espresso UI测试被取消,没有错误信息。

16

运行UI测试时遇到了问题。 enter image description here

但是ExampleInstrumentedTest正常运行。

这是我的测试文件,我已经注释掉了所有内容,只剩下一个空函数。


@RunWith(AndroidJUnit4ClassRunner::class)
class ExploreFragmentTest {

    @get: Rule
    val activityRule = ActivityScenarioRule(MainActivity::class.java)

    @Test
    fun test_isSearchButtonDisplayed() {
        //onView(withId(R.id.btn_search)).check(matches(isDisplayed()))
    }
}

这是我的应用程序/ gradle中的依赖关系

    // AndroidX Test - Instrumented testing
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'androidx.test:rules:1.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'

如何查看实际错误信息?

我们可以在错误反馈方面做得更好吗?


1
这里也会发生这种情况。你发现是什么了吗? - kaneda
2
这意味着应用在运行测试时崩溃了。在我这种情况下是 Segment Analytics 尝试在测试环境中进行网络调用。错误消息很差劲。 - BabyishTank
1
谢谢,这非常有帮助。我的情况和你的一样。只是在查看 Crashlytics 后才找到了答案。 - kaneda
这个答案对我解决了问题。https://stackoverflow.com/a/77271279/1441731 - undefined
2个回答

6

这对我来说是由于使用x86模拟器引起的。当我切换到x86_64后,API 30及以下的问题停止了;然而,我仍在使用API 31时遇到了此问题。


4

我遇到了相同的错误。

我使用adb和logcat查看日志:adb logcat

我在我的日志中找到了这个错误:

java.lang.NoSuchMethodError: No static method registerDefaultInstance(Ljava/lang/Class;Lcom/google/protobuf/GeneratedMessageLite;)V in class Lcom/google/protobuf/GeneratedMessageLite; or its super classes (declaration of 'com.google.protobuf.GeneratedMessageLite' appears in /data/app/~~BuZ1RxiHRJybZNpyUcjGIw==/-xuI8WeeYUojtsn-ncVI-aw==/base.apk)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at com.google.firebase.perf.v1.ApplicationInfo.<clinit>(ApplicationInfo.java:1085)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at com.google.firebase.perf.v1.ApplicationInfo.newBuilder(ApplicationInfo.java:533)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at com.google.firebase.perf.transport.TransportManager.finishInitialization(TransportManager.java:226)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at com.google.firebase.perf.transport.TransportManager.syncInit(TransportManager.java:220)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at com.google.firebase.perf.transport.TransportManager.$r8$lambda$LuAwHBxy50Yf-ziHqcD54KjEPtk(Unknown Source:0)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at com.google.firebase.perf.transport.TransportManager$$ExternalSyntheticLambda1.run(Unknown Source:2)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
01-30 08:23:34.286  5932  6012 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:920)

为了解决这个问题,我在我的 build.gradle 文件中排除了 androidx.test.espresso:espresso-contrib:3.4.0 中的 protobuf-lite: protobuf-lite
androidTestImplementation ("androidx.test.espresso:espresso-contrib:3.4.0") {
    exclude module: "protobuf-lite"
}

现在我的测试可以正常工作了!


你还需要从androidx.test.espresso:espresso-accessibility:3.4.0中排除protobuf-lite - B3n
这个解决方案之前有效了一段时间,现在又出现了:/ - YellowJ

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接