How do you write integration tests for Firestore on Unity?

Viewed 287

I have a Unity3D app backed by a Firebase/Firestore database.

Firebase provides a Local Emulator Suite for testing, but it is not supported on Unity.

It seems the only way to test logic which uses Firestore is to either:

  1. Use a real, test-only database and clear it on each SetUp
  2. Mock out all usages of Firestore

(2) seems error-prone and like I'm reinventing the wheel. (1) seems both dangerous and slow. Is there another widely-supported option I'm missing?

1 Answers

The emulator suite is now supported. See https://github.com/firebase/quickstart-unity/issues/719#issuecomment-938759588

To use the emulator, run

FirebaseFirestore firestore = FirebaseFirestore.DefaultInstance;
firestore.Settings.Host = "localhost:8080";
firestore.Settings.SslEnabled = false;

Make sure you use this code in each assembly used. Many tutorials have the tests run in a separate assembly as the rest of your code. If your architecture is similar, you will need the above code in each assembly. Specifically, be sure to call this code both in your test assembly when accessing FirebaseFirestore.DefaultInstance, and in your game code, since FirebaseFirestore.DefaultInstance exists once per process (i.e. once per assembly).

Related