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'
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!