September 21, 2021

Firebase | Firestore | Firestore junit test | deep stubbing mockito

This is a sample code how to perform deep stubbing mockito on firestore
you need to mock all the 


public class FirestoreClientTest{

@Mock
Firestore firestore;

@Mock
DocumentReference documentReference;

@Mock
CollectionReference collectionReference;

@Mock
ApiFuture apiFuture;

@Mock
QuerySnapshot querySnapshot;

@Test
public void test(){
when(firestore.collection(any(String.class)).thenReturn(collectionReference);
when(collectionReference.document(any(String.class)).thenReturn(documentReference);
when(documentReference.get()).thenReturn(apiFuture);
when(apiFuture.get()).thenReturn(querySnapshot);

UserInfo userInfo = firestore.getUserDetails();

//Assert statements
}

}

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments