Skip to content

Testing Guide

Oskar Zanota edited this page Nov 25, 2024 · 4 revisions

Please read carefully the following instructions to consider when writing tests, or code that will be tested. These guidelines emerged after fixing this issue. See also this pull request.

TearDown

All UI tests should extend the TearDown class, like so:

class MyTest : TearDown() {

When extending this class, state is automatically cleaned up between tests. If needed, you can override the tearDown method but make sure to call its super-implementation.

Note that this concerns only UI tests. End to end tests should extend the EndToEndTest class.

Tests using FirestoreReferenceList

For tests calling FirestoreReferenceList.requestAll(), it is crucial to make a static mock of Firebase.firestore. Otherwise, the end to end tests will fail because the .requestAll acts as a Firebase initialisation, preventing the end to end tests from reinitialising the Firebase instance with the local emulator.

3. Adding AuthStateListeners

Firebase’s AuthStateListeners persist between tests. In order to remove them between tests, any listener must be registered like so:

Firebase.auth.registerAuthStateListener { ... }

And not the previous .addAuthStateListener.