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.