I am trying to setup flutter scripts for testing my classes that interface with my firestore database.
My current struggles are:
- It seems that in order to use firebase_auth, I have to have a widget tree. I'm new to both flutter and firebase I am slowly building up my expertise by building classes one at a time, writing tests for them and then moving to the next class. Requiring the widget tree means I can't test the authorization logic independent of the GUI (e.g. What happens if I call signOut twice in my code even though the GUI logic only lets you press the button once?).
- Mocking is insufficient. In order to mock, you need to know the expected behaviour for the tests to be representative. I've spent a lot of time trying to troubleshoot issues with futures, changing signed in states, and incorrect data formats. If I had written mocks, they wouldn't have matched how the real functions actually behave.
- Mocking doesn't help me as I am also learning about the security rules for the database. I've definitely got code that works with lax security rules but there's something wrong with the current security rules.
Is there any way to write unit/integration tests for firebase_auth or firestore without mocking? I'm even happy using a local emulator/export of my database if that's a thing that's even possible.
Here are a number of the articles I have reviewed that are not what I am looking for:
- A month of Flutter: mocking Firebase Auth in tests
- Setup Unit test for Firebase User authentication with Mockito
- How to create integration test for app with Firebase Auth?
- Flutter Testing [4] - Firebase Auth App - Unit Testing
- Mocking In Integration Tests with Flutter
- Writing Unit Tests in Flutter with Firebase Firestore
- Tutorial how to test with firebase #15245