Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to unit test some Firestore functionality like so:

@Test
public void ratingTest() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    FirebaseUtils.doTask(1, new FirebaseUtils.OnComplete() {
        @Override
        public void onSuccess() {
            //assertions
            latch.countDown();
        }

        @Override
        public void onFail() {
            //assertions
            latch.countDown();
        }
    });
    latch.await();
}

But I'm getting the following error:

Caused by: java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked. See http://g.co/androidstudio/not-mocked for details.
    at android.os.Looper.getMainLooper(Looper.java)
    at com.google.firebase.FirebaseApp$UiExecutor.<clinit>(FirebaseApp.java:696)

I've already found a supposed solution, which involves adding the following the the test class:

@Rule
public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule();

And this to the gradle:

testImplementation 'androidx.arch.core:core-testing:2.1.0'

This does not seem to make a difference and I can't find any other solutions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
490 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...