Repository navigation
Unit test firestore: Mocking DocumentReference and CollectionReference #3263
Copy link
Copy link
Closed
Labels
api: firestoreIssues related to the Firestore API.Issues related to the Firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.status: blockedResolving the issue is dependent on other work.Resolving the issue is dependent on other work.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Description
Activity
Thanks for sending this over. I filed an internal issue and will update you as we make progress.
- addedtriage meI really want to be triaged.I really want to be triaged.🚨 criticalP0 critical issue. Requires immediate fixP0 critical issue. Requires immediate fix
on Jun 8, 2018 - addedtype: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.status: blockedResolving the issue is dependent on other work.Resolving the issue is dependent on other work.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.api: firestoreIssues related to the Firestore API.Issues related to the Firestore API.and removedtriage meI really want to be triaged.I really want to be triaged.🚨 criticalP0 critical issue. Requires immediate fixP0 critical issue. Requires immediate fix
on Jun 11, 2018 We need them too for unit testing purposes
Looks like the constructor of CollectionReference was missed in the fix
Follow up PR: #6054
- added a commit that references this issue
on Mar 9, 2026
Metadata
Metadata
Assignees
Labels
api: firestoreIssues related to the Firestore API.Issues related to the Firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.status: blockedResolving the issue is dependent on other work.Resolving the issue is dependent on other work.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
We are trying to test classes with dependencies on firestore and we found we cannot mock these classes because their constructors are internal. Is it possible if the following methods return interfaces instead of classes:
val collectionReference:CollectionReference = db.collection(collectionName)
val document: DocumentReference = collectionReference.document(docId)