Is there way to emulate Firebase Database locally?

Viewed 2254

I think question title is self explanatory, however following are more details

Background

I am developing one turn based android game with the help of Firebase realtime database. Concept is very simple, all players are connected to single room which I create by pushing into firebase database. Now every player attaches child value listener to that node. Now I can update game status in this node and everyone will get update in real time.

Problem

During development phase, I am still trying out different ways to structuring this data and implementing in android client. I am not working on any company or enterprise hence I have to use my own mobile internet (where internet data is costly). Plus many times I am in area where there is no internet connectivity. This reduces amount of time spent on testing any network related testing.

Question

Is there way I can simulate (or emulate) firebase database locally ? So that once it is working fine, I can test it on real network ? Any ideas or hints regarding this will be helpful.

2 Answers

It sounds like you probably want to try firebase-server. It is basically a replacement Real-Time Database server that you can run locally.

You need to edit your OS's hosts file to make a 3-part domain name (like localhost.firebaseio.test) resolve to localhost, because of some weird restrictions built into the Firebase client libraries. Some people have found a way around this by injecting mocks into the client library, but this never worked for me; I think it only worked in an old version.

Note that this is NOT the officially recommended way to write unit tests; it's considered better to totally mock out the Firebase client library. It can be quite useful for integration tests, though.

There's a useful thread here that covers some testing questions.

Related