Issue
I'm trying to create tests in compose and I'm always getting the following error:
Default FirebaseApp is not initialized in this process X. Make sure to call FirebaseApp.initializeApp(Context) first.
I've tried to simplify the most the code of the test:
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun test() {
composeTestRule.setContent {
Text("Whatever")
}
}
but still getting that error.
I've tried with uiThreadTestRule:
@get:Rule
val composeTestRule = createComposeRule()
@get:Rule
var uiThreadTestRule: UiThreadTestRule = UiThreadTestRule()
@Test
fun test() {
uiThreadTestRule.runOnUiThread {
FirebaseApp.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
}
composeTestRule.setContent {
Text("Whatever")
}
}
and also with the same composeTestRule.runOnUiThread:
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun test() {
composeTestRule.runOnUiThread {
FirebaseApp.initializeApp(InstrumentationRegistry.getInstrumentation().targetContext)
}
composeTestRule.setContent {
Text("Whatever")
}
}
How can that FirebaseApp is not initialized
error be fixed so that the composables of this app can be tested?
Update
It seems to be something about the createComposeRule() cause the following test:
@get:Rule
val composeTestRule: ComposeContentTestRule = createComposeRule()
@Test
fun test() {
assertEquals(2, 1 + 1)
}
also fails and it passes if I remove the rule. I don't need the firebase dependency in the tests if it's possible to remove it.
Solution
Add this into the gradle file of that module to exclude the firebase dependency:
configurations {
androidTestImplementation {
exclude group: 'com.google.firebase', module: 'firebase-perf'
}
}
Answered By - jeprubio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.