FrangSierra/RxFirebase

Cannot write tests for to mock static RxFirebase methods

william-reed opened this issue · 5 comments

One of the issues I am running into is writing tests for code that uses RxFirebase.

In these classes I usually inject FirebaseAuth or whatever and pass it in to the static calls to RxFirebaseAuth. Since the methods in RxFirebaseAuth are static I am not able to mock them out during my tests to return some data of my choice. I can mock out FirebaseAuth itself but it likely will require dealing with some more levels of mocking than I should need to.

Being able to mock out RxFirebaseAuth methods would solve this. I am not sure if that means offering non static methods for this purpose and I am also curious if others have found workarounds to this

Why would you want to mock RxFirebaseAuth methods? You can just mock the real Firebase implementations(that it's what RxFirebase use), and the methods will work perfectly.
Just check the tests on the library as an example.

Hope that it will help you.

@FrangSierra it seems excessive that in order to test it you need to setup all the stuff that goes on under the hood yourself. E.g. you need to setup the argument captors, the tasks of different types and all that

I might try adapting some of the testing utils to throw it into the actual library to make it easier for users to write their own tests. I'll continue to look into it

After messing around the easiest method is definitely to be able to mock these static classes. Its excessive to have to mock the underlying Firebase* objects as well. I would argue for the addition of such an ability without requiring frameworks to support static mocking

Hello @william-reed ,

if you find a good way to do it. Please, be my guest and send a PR.
This should be easy to do if the library would be written in Kotlin using mockito 2. But migrate it to Kotlin will be also ankward for a lot of users who use it atm.