5

Having an app based on firebase DB - where items are loaded asynchronously (e.g. into RecyclerView) via Firebase callbacks - how would we define Espresso check?

Using a custom IdlingResource seems problematic, because ChildEventListener's onChildAdded callback, does not tell us whether a given child is the last one (or does it?).

Is there a way to tell when Firebase is "idle"?

Is it perhaps against the spirit of Firebase to consider it "idle" at any time?

Then perhaps we can define "locally idle"? Meaning no locally initiated request callbacks (to fetch initial items) are pending... (as opposed to new stuff that can come from the network at any time).

KarolDepka
  • 8,318
  • 10
  • 45
  • 58

1 Answers1

5

Tests should be hermetic: you shouldn't have dependencies on external data sources.

Create a product flavor where you replace the Firebase data source with a fake one, only used in tests. This lets you test with fake data, for repeatable tests.

This concept is explained in Leveraging product flavors in Android Studio for hermetic testing

And it's implemented in Android Architecture Blueprints

The caveat is that you're not going to test the integration between Firebase and your app, but those tests tend to be flaky.

Jose Alcérreca
  • 1,809
  • 17
  • 20