#StackBounty: #android #mockito #firebase-analytics Firebase Analytics initialise for unit test (Mockito) in Android

Bounty: 50

I am running a unit test with

@RunWith(MockitoJUnitRunner.class)

I have used firebase Analytics to log events

MyApplication.getAnalytics().getInstance(appContext).logEvent(eventType, bundle)

and this in my Application class

public static FirebaseAnalytics getAnalytics() {
        return FirebaseAnalytics.getInstance(appContext);
    }

Now while running tests, I am getting NullPointerException. What will be the right way to initialize Analytics for my unit tests or just ignore them.

I am not getting the context in case I try to initialize it in my setup method of tests.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.