-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The mystery of Unit Testing with Firestore #17
Comments
Hi @chstrong. I also struggled a lot with testing Firestore and finally, I used the cloud_firestore_mocks package. It's still tricky but did the trick. You can check my code for examples. To test a bloc, primary you'll need the bloc_test package. With it, it's pretty easy to implement unit testing in blocs. Again, you could check my code for examples. |
THIS WORKS FOR ME. I was having a lot of trouble trying to test widgets that use BloCs, whose repositories communicate with Firebase. 1. These are my imports and the annotations used to auto-generate the mocks for my IBlaBlaRepository: import 'package:bethemis_abogados/application/chat/message_watcher/message_watcher_bloc.dart'; import 'casedashboard_widget_test.mocks.dart'; @GenerateMocks([ 2. This is the "stream" variable that I want to be returned by one of my Repository methods. var messageAux = Message( 3. And, finally, here's a look at the testWidgets method. testWidgets(
); |
Dear Resocoder,
Your tutorial is absolutely fantastic.
However, one mystery remains, and this is unit testing the NoteRepository class and the NoteWatcherBloc, and NoteActorBloc class with Firestore.
This is therefore a "feature" request.
Your tutorial is great but can get very complex for amateur programmers. So I'm trying a test-driven approach for your domain driven tutorial, in order to solve each concern separately. I'm starting therefore with the domain and infrastructure / repository layer.
Mockito doesn't seem to be able to accept constructors and hence I can't pass a Mock instance of Firebase to the repository, or the Bloc. At the moment I'm thinking of writing an additional method in the NoteRepository which I can use to parse the Firebase Mock instance, but I'm sure you will scream at me and tell me it's not good code practice :) And the problem with the Bloc still remains.
I think a separate video would be helpful that explains how to test repository and bloc classes with Firestore.
There is nobody, that is showing this, so it seems to be a complex topic that nobody can copy, as there are no examples :).
Or all use AWS Lambda with JSON and nobody uses Firebase :)
All are showing FirebaseAuth, but nobody shows how to test repository classes and blocs. I didn't figure out how to do it yet but am working on it.
The text was updated successfully, but these errors were encountered: