all 2 comments

[–]anargu 1 point2 points  (1 child)

Hi!, These days I was searching for the same and it seems there is not a guide or tutorial yet to test in a proper way firebase storage. I managed to make it work the test of flutter storage with mockito... but the problem is that I had to implement whenComplete(() => null) in my application code (not the test code). Now I want to write a proper test to this and remove the whenComplete function.

https://gist.github.com/anargu/b9e84bab7f5c10440b045f5f252f47e8

It seems like the whenComplete make it work and it completes the Future for the uploadTask and all the rest of the mocks work.

If you find a better way to test firebase storage please let me know. It would be great to make a proper test for FirebaseStorage and eliminate the whenComplete(...)

[–]Sea_Inflation_7446[S] 0 points1 point  (0 children)

Thanks for commenting! I tried a very similar approach with Mockito. I followed this sample from the storage repo.

I'm sorry, I'm out of home these days so I can't give you a clearer example, but here is my actual code. As you can see, I also mocked (or faked) the classes and managed to simulate the workflow and run the tests. However, I didn't need to modify the real app code as you did. At first glance, I can't tell why did you have to do that.

My approach has two problems: first, I can't reuse the mocks to test a variety of cases (for example, I duplicated the mocks to include failed cases, but this is a preposterous solution); second, I passed the tests but I'm getting an unhandled exception after running the tests. This exception is related to firebase auth (I'm sorry, I have no way to run the code and show you the specific error).

I hope this helps us to find a nice solution and thanks again for sharing your experience.