This guide describes how to run an XCTest or a Game Loop test using the gcloud CLI.
Step 1: Configure your local Google Cloud SDK environment
- Download the Google Cloud SDK
- Make sure your installation is up-to-date and includes
gcloud components update
- Log in to the gcloud CLI using your Google account:
gcloud auth login
- Set your Firebase project in gcloud, where PROJECT_ID is
the ID of your Firebase project:
gcloud config set project PROJECT_ID
This includes the gcloud CLI tool.
Step 2: Run your test
Run an XCTest
Upload the .zip file of your test by running the following command (if you haven't yet packaged up your app, see Packaging your XCTest):
cd FOLDER_WITH_TEST_OUTPUT/Build/Products ; \ zip -r MyTests.zip Debug-iphoneos YOUR_SCHEME_iphoneosDEPLOYMENT_TARGET-arm64.xctestrun
Choose your test dimensions.
Test Lab lets you run tests on a variety of iOS versions, devices, screen orientations, and locales. These configurations are known as the test's test dimensions. To see the options for each dimension (e.g., supported Xcode versions for the device's iOS version), substitute
dimensionin the following command:
gcloud firebase test ios dimension list
Screen orientation is somewhat simpler, as its only options are
Look through the list of test dimensions, and select a few combinations that you'd like to run your test on. Visit Pricing Plans to see the maximum number of combinations you can run per day.
Once you've chosen a set of test dimensions, you can have Test Lab run your tests using the
firebase test ios runcommand. For each combination of test dimensions you'd like to test on, include a separate
gcloud firebase test ios run --test PATH/TO/MyTests.zip \ --device model=MODEL_ID_1,version=VERSION_ID_1,locale=LOCALE_1,orientation=ORIENTATION_1 \ --device model=MODEL_ID_2,version=VERSION_ID_2,locale=LOCALE_2,orientation=ORIENTATION_2 \ etc...
It is possible that your test will fail due to an incompatibility between the Xcode version with which the test was built and the default Xcode version used by Test Lab. To specify a supported Xcode version for your test, use the
gcloud firebase test ios run --test PATH/TO/MyTests.zip \ --device model=MODEL_ID_1,version=VERSION_ID_1,locale=LOCALE_1,orientation=ORIENTATION_1 \ --xcode-version=11.3
To help you identify and locate your test matrices in the Firebase console, you can optionally label your test matrix using the
--client-details matrixLabel="<label>"flag in the following example:
gcloud beta firebase test ios run --test PATH/TO/MyTests.zip \ --device model=MODEL_ID_1,version=VERSION_ID_1,locale=LOCALE_1,orientation=ORIENTATION_1 \ --client-details matrixLabel="my label"
Test Special Entitlements
To test entitlements that require an explicit App ID, you can do so by
--test-special-entitlements flag. Test Lab
re-signs the application with a new bundle-identifier to support special
entitlements, so please make sure there are no resources in your zip file
containing direct references to the app's bundle id.
For authorizing push notification requests, users can create JSON web tokens by using the private signing key along with the Key ID - C7FD9DJAA8 and the Team ID - 9CKCGNNUQN. The generated tokens would be valid for one hour and need to be refreshed every 60mins. Read more on Establishing a Token-Based Connection to APNs.App groups
App group IDs are universally unique. This means that when we re-sign user apps, we can only use the app group ID that is associated with the Test Lab developer account. If your test relies on app groups, your test will fail.
Run a Game Loop test
gcloud beta firebase test ios run command and use the following
flags to configure the run:
|Flags for Game Loop tests|
Required: Specifies the type of iOS test you want to run. You can enter
Required: Absolute path (GCS or filesystem) to your app’s IPA file. This flag is only valid when running Game Loop tests.
The loops (aka scenarios) you want to run in your app. You can enter one loop, a list or loops, or a range of loops. The default loop is 1.
The physical device you want to run your test on (find out which available devices you can use).
The maximum duration you want your test to run. You can enter an integer to represent the duration in seconds, or an integer and enumeration to represent the duration as a longer unit of time.
For example, the following command runs a Game Loop test that executes loops 1, 4, 6, 7, and 8 on an iPhone 8 Plus:
gcloud beta firebase test ios run --type game-loop --app path/to/my/App.ipa --scenario-numbers 1,4,6-8 --device-model=iphone8plus
For more information on the gcloud CLI, see the reference documentation.
Step 3 (Optional): Automate future tests you build
Scripting gcloud commands with Test Lab
You can use shell scripts or batch files to automate mobile app testing commands that you would otherwise run using the gcloud command line. This sample bash script runs an XCTest with a two-minute timeout, and reports if the test run completed successfully:
if gcloud firebase test ios run --test MyTest.zip --timeout 2m then echo "Test matrix successfully finished" else echo "Test matrix exited abnormally with non-zero exit code: " $? fi
Script exit codes
Test Lab provides several exit codes that you can use to better understand the results of tests that you run using scripts or batch files.
|0||All test executions passed.|
|1||A general failure occurred. Possible causes include: a filename that does not exist or an HTTP/network error.|
|2||Testing exited because unknown commands or arguments were provided.|
|10||One or more test cases (tested classes or class methods) within a test execution did not pass.|
|15||Firebase Test Lab could not determine if the test matrix passed or failed, because of an unexpected error.|
|19||The test matrix was canceled by the user.|
|20||A test infrastructure error occurred.|
Step 4: Investigate test results
When the test starts, you receive a link to the Test Results page. Tests can take a number of minutes to run, depending on the number of different configurations you have selected and the test timeout duration set for your tests. After your tests have run, you can review test results. See Analyzing Firebase Test Lab Results to learn more about how to interpret your test results.