Firebase.analytics fails in instrumentation test

26 views Asked by At

In one of my onClick listeners in Compose, I call:

Firebase.analytics.logEvent("hi", null)

While this works in production code, it fails when running an Instrumentation Test with the message:

10-02 17:45:24.261 10389 10423 E TestRunner: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process app.elektra.presentation.test. Make sure to call FirebaseApp.initializeApp(Context) first.
10-02 17:45:24.261 10389 10423 E TestRunner:    at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:179)
10-02 17:45:24.261 10389 10423 E TestRunner:    at com.google.firebase.ktx.FirebaseKt.getApp(Firebase.kt:42)
10-02 17:45:24.261 10389 10423 E TestRunner:    at com.google.firebase.analytics.ktx.AnalyticsKt.getAnalytics(com.google.firebase:firebase-analytics-ktx@@21.3.0:5)

However if I replace my code with FirebaseAnalytics.getInstance(context).logEvent(...) the test also passes. I still want to use Firebase.analytics though, since I don't have to pass the context.

What am I missing?


  • Firebase bom version: 32.3.1
  • com.google.gms:google-services version: 4.3.15
0

There are 0 answers