Make it easier for Mocking #3229
Replies: 3 comments
-
Keen to help here, maybe we could expose a few things internally for testing only. Need to investigate, so any ideas much appreciated. |
Beta Was this translation helpful? Give feedback.
-
I would start by creating a demo App that uses most of the services, Auth, Firestore, Crashlytics, trying to use them as the best practices recommend, Dependency Injection, you know, then try to create tests for that App and see how's your experience trying to mock and inject the Firebase services. This way you won't be speculating, but actually seeing the user experience first hand. For example, you could inject a Repository that uses Firestore internally, so tests would inject a Fake repository (that's easy), but when you want to test the repository itself you would need to inject a fake Firestore instance. With that you could come up with a more uniform way to mock the services, then the packages could provide some fake implementations under the What I suspect you will come up in the end is a more "pluggable" interface, instead of all of these private constructors. You could use the Also IIRC you construct some fake I am just thinking out loud here to be honest, but I think this is a step in the right direction and people experienced with tests in Dart should give some hints as well. It would also be interesting to have a small guideline for tests into the docs. |
Beta Was this translation helpful? Give feedback.
-
I would love to be able to test especially Firestore easily! |
Beta Was this translation helpful? Give feedback.
-
Currently the Firebase architecture uses Singletons which we need to retrieve using
instance
with private constructors, which makes mocking cumbersome.Copying the tests here is also not great as the Mocks themselves are pretty complicated.
I think the architecture should be rethinked so testing, mocking the Firebase services on our Apps could be easier to implement with Mockito.
As an example, lets look at your own tests here, you use:
setupFirebaseAuthMocks()
MockPlatformInterfaceMixin
Which are all external references and this makes our apps really hard to Mock. It sure helps your library to be tested, but not so much we as the users to test our own Apps.
Beta Was this translation helpful? Give feedback.
All reactions