3

im trying to write test with roboelctric, but when i called:

ActivityScenario<LogInActivity> logInActivity = ActivityScenario.launch(LogInActivity.class);

i got an error:

java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process null. Make sure to call FirebaseApp.initializeApp(Context) first.

(in the activity, the firebase is initialize but on the test it isn't) how do i slove it? :)

test class:

@RunWith(AndroidJUnit4.class)
public class LogInActivityTest {

    @Before
    public void setUp() {
        ActivityScenario<LogInActivity> logInActivity = ActivityScenario.launch(LogInActivity.class);

    }

    @Test
    public void some_test() {
        // WHEN
        Espresso.onView(ViewMatchers.withId(R.id.phoneEditText)).perform(click());


}

    }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
DVIR
  • 51
  • 3
  • It sounds like the process gets initialized before Firebase can get to it. Did you try explicitly initialize `FirebaseApp`, as the message says? See https://stackoverflow.com/questions/45977847/make-sure-to-call-firebaseapp-initializeappcontext-first-in-android for an example. – Frank van Puffelen Sep 14 '19 at 01:15
  • thank you very much for the answer! :) but it didn't work: java.lang.IllegalStateException: java.lang.RuntimeException: java.io.IOException: The filename, directory name, or volume label syntax is incorrect – DVIR Sep 14 '19 at 01:38
  • and by the way, i am a big fan of your videos! :) – DVIR Sep 14 '19 at 01:41
  • You'll want to show what code you added where to get that error. I must admit that adding this code in an activity is usually not great, and it should probably go into a `ContentProvider`. – Frank van Puffelen Sep 14 '19 at 03:03
  • oh sorry, i tried to put it in the setUp() method of the test above, and in the activity OnCreate(), but the result was the same. – DVIR Sep 14 '19 at 03:31
  • and the code in the activity: FirebaseApp.initializeApp(this); and in the test: FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext()); – DVIR Sep 14 '19 at 03:36
  • Did you get this resolved? I am having the same issue – w3bMak3r Sep 11 '20 at 17:08
  • Same here, like to know the answer – JPM Oct 15 '20 at 20:26

0 Answers0