How do you unit test your code with firebase?

2,913 views
Skip to first unread message

Houman K.

unread,
Apr 20, 2017, 9:52:40 AM4/20/17
to Firebase Google Group
Hello,

I'm surprised to see so little about unit testing with Firebase.  I'm connecting to Firebase via an iOS app, and my unit tests point to a separately hosted firebase project. This is anything but ideal, as I need to have an open connection to the internet to run my tests. 

I worked with Google App Engine previously and I really appreciated that they have a single threaded local environment for unit testing.

How comes there is nothing for firebase? How are unit testing supposed to be done? 

Thank you,
Houman


Doug Stevenson

unread,
Apr 21, 2017, 10:40:17 AM4/21/17
to Firebase Google Group
Houman,

A true unit test for some bit of code has zero external dependencies.  This includes removing Firebase backend services completely from the test.  Instead of calling into Firebase APIs normally, you would mock the Firebase APIs and make those mocks generate exactly what you expect for the test to run with 100% consistency and maximum speed.

If you do need to test interactions against a backend - you might call this "integration testing" or "end to end testing" - then you may as well continue doing what you're saying: use a special project whose database contents and rules are established ahead of time.  There would be no distinct advantage to having a "local" Firebase service, other than speed.  And that wouldn't be a true integration test anyway.

Doug

Alan deLespinasse

unread,
Apr 21, 2017, 12:30:09 PM4/21/17
to Firebase Google Group

Houman K.

unread,
Apr 22, 2017, 6:45:10 PM4/22/17
to Firebase Google Group
Thanks Alan,  I had looked into firebase-server.  It looks very promising for Javascript developers, but I wasn't able to connect to it via SWIFT. There is no tutorial or documentation out there. This would actually solve my problem 100% if I could get it to work.

Houman K.

unread,
Apr 22, 2017, 6:45:16 PM4/22/17
to Firebase Google Group
Thanks Doug,

I agree with you.  But being new to Firebase and applying TDD, I need to know if my query or save methods actually work.  Mocking everything but the actual method calls won't really add any value in my case.
Reply all
Reply to author
Forward
0 new messages