Here is the problem when I run my UI test.
But the ExampleInstrumentedTest is working.
This is my test file, I already comment out everything, leaving an empty function
@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()))
}
}
Here is my dependency in 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'
The Espresso test framework. Espresso is a testing framework for Android to make it easy to write reliable user interface tests. Google released the Espresso framework in Oct. 2013. Since its 2.0 release Espresso is part of the Android Support Repository.
Espresso is an open source android user interface (UI) testing framework developed by Google. The term Espresso is of Italian origin, meaning Coffee. Espresso is a simple, efficient and flexible testing framework.
I had the same error.
I used adb and logcat to view the logs: adb logcat
I found this error in my logs:
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)
To fix that, I excluded protobuf-lite
from androidx.test.espresso:espresso-contrib:3.4.0
in my build.gradle
file:
androidTestImplementation ("androidx.test.espresso:espresso-contrib:3.4.0") {
exclude module: "protobuf-lite"
}
And now my test works!
for me this was caused by using an x86 emulator. when I switched to x86_64 the problem stopped for APIs 30 and below; however, I still have this issue using API 31.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With