Firebase Android libraries exercise all three types of tests recommended by the
Android Testing Pyramid.
Depending on the requirements of the specific project, some or all of these tests may be used to
support changes.
:warning: Running tests with errorprone
To run with errorprone add withErrorProne to the command line, e.g.
./gradlew :<firebase-project>:check withErrorProne.
Unit Testing
These are tests that run on your machine's local Java Virtual Machine (JVM). At runtime, these tests
are executed against a modified version of android.jar where all final modifiers have been stripped
off. This lets us sandbox behaviors at desired places and use popular mocking libraries.
Unit tests can be executed on the command line by running
./gradlew :<firebase-project>:check
Integration Testing
These are tests that run on a hardware device or emulator. These tests have access to
Instrumentation APIs, give you access to information such as the
Android Context. In Firebase,
instrumentation tests are used at different capacities by different projects. Some tests may
exercise device capabilities, while stubbing any calls to the backend, while some others may call
out to nightly backend builds to ensure distributed API compatibility.
Along with Espresso, they are also used to test projects that have UI components.
Project Setup
Before you can run integration tests, you need to add a google-services.json file to the root of
your checkout. You can use the google-services.json from any project that includes an Android App,
though you'll likely want one that's separate from any production data you have because our tests
write random data.
If you don't have a suitable testing project already:
- Open the Firebase console
- If you don't yet have a project you want to use for testing, create one.
- Add an Android app to the project
- Give the app any package name you like.
- Download the resulting
google-services.json file and put it in the root of your checkout.
Running Integration Tests on Local Emulator
Integration tests can be executed on the command line by running
./gradlew :<firebase-project>:connectedCheck
Running Integration Tests on Firebase Test Lab
You need additional setup for this to work:
gcloud needs to be installed on local machine
gcloud needs to be configured with a project that has billing enabled
gcloud needs to be authenticated with credentials that have 'Firebase Test Lab Admin' role
Integration tests can be executed on the command line by running
./gradlew :<firebase-project>:deviceCheck
This will execute tests on devices that are configured per project, if nothing is configured for the
project, the tests will run on model=panther,version=33,locale=en,orientation=portrait.
Projects can be configured in the following way:
firebaseTestLab {
// to get a list of available devices execute `gcloud firebase test android models list`
devices = [
'<device1>',
'<device2>',
]
}