【问题标题】:Espresso UI Test Cancelled with no error messageEspresso UI 测试已取消且没有错误消息
【发布时间】:2025-12-26 02:55:07
【问题描述】:

这是我运行 UI 测试时的问题。

但 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()))
    }
}

这是我在 app/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'

仍在寻找答案:如何查看实际的错误信息???

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

【问题讨论】:

  • 这里也发生了。你发现它是什么了吗?
  • 这意味着应用程序在运行测试时崩溃了。在我的例子中,分段分析试图在测试环境中进行网络调用。糟糕的错误信息。
  • 谢谢,这很有帮助。我的情况和你的一样。看了 crashlytics 就知道了。

标签: android android-espresso ui-testing


【解决方案1】:

我有同样的错误。

我用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

androidTestImplementation ("androidx.test.espresso:espresso-contrib:3.4.0") {
    exclude module: "protobuf-lite"
}

现在我的测试成功了!

【讨论】:

  • 您还必须从androidx.test.espresso:espresso-accessibility:3.4.0 中排除protobuf-lite