android - Espresso UI 测试已取消且没有错误消息

标签 android android-espresso ui-testing

这是我运行 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()))
    }
}
这是我在 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'
如何查看实际的错误信息???
我们可以在错误反馈上做得更好吗?

最佳答案

我有同样的错误。
我使用 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)
为了解决这个问题,我排除了 protobuf-lite来自 androidx.test.espresso:espresso-contrib:3.4.0在我的build.gradle文件:
androidTestImplementation ("androidx.test.espresso:espresso-contrib:3.4.0") {
    exclude module: "protobuf-lite"
}
现在我的测试成功了!

关于android - Espresso UI 测试已取消且没有错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68976841/

相关文章:

android - Gradle JUnit android 运行除 @FlakyTest 之外的所有内容

android - 适用于 Windows 的 OSX 模拟器 |与 ionic 框架一起使用

android - 如何使用 Jetpack Compose 在 TopAppBar 中设置渐变背景

java - 在三个 fragment 之间共享 ViewModel

android-espresso - AndroidInjector 和 Espresso

android - Espresso : click first item in ListView inside a ViewPager

c# - 无法使用 autoAcceptAlerts 在 iOS 上运行 Appium 测试

java - Espresso : Interact with Play Store Popup

angular - 无法找到元素的可测试性 - Protractor

android - 原因 : lateinit property _buildFeatureValues has not been initialized