Before you proceed with the steps listed below, make sure that you’ve completed the native setup guide.
Overview
Firebase Test Lab is Google’s cloud-based testing infrastructure that provides access to physical and virtual devices. It’s particularly popular in the Flutter community due to its integration with Google Cloud Platform and competitive pricing.Prerequisites
Install gcloud CLI
You need the
gcloud command-line tool to interact with Firebase Test Lab. Install it from the official documentation.After installation, authenticate with your Google Cloud account:Running Tests on Android
Build APKs
Patrol needs to build two APKs for Android testing:
- The app under test (your Flutter app)
- The test instrumentation app (contains the test code)
You can specify multiple test files by using comma separation:
Run tests on Firebase Test Lab
Use the
gcloud CLI to upload and run your tests:Understanding the flags:
--type instrumentation- Specifies that this is an instrumentation test--use-orchestrator- Enables Android Test Orchestrator for isolated test execution--app- Path to your app APK--test- Path to your test APK--timeout- Maximum test execution time--device- Device configuration (model, OS version, locale, orientation)--record-video- Records video of the test execution--environment-variables clearPackageData=true- Clears app data between tests
Advanced Android Configuration
Testing on multiple devices
Testing on multiple devices
You can test on multiple devices in parallel by specifying multiple
--device flags:Managing permissions
Managing permissions
By default, all permissions are granted automatically on Firebase Test Lab. To control this behavior, use the alpha version of gcloud:Learn more in the gcloud documentation.
Automated script
Automated script
Create a shell script to avoid typing long commands. Here’s an example:Make it executable:See the Patrol example app’s script for a production-ready version.
run_android_testlab.sh
Running Tests on iOS
Build iOS apps
Patrol needs to build two iOS apps:For physical devices:The command outputs the paths to the built artifacts:
- The app under test (your Flutter app)
- The test instrumentation app (contains the test code)
Run tests on Firebase Test Lab
Upload and execute the tests:
If your
.xctestrun file has a different iOS version in its name than the device you’re testing on, simply rename the file to match. For example, if testing on iOS 16.6 but your file is named Runner_iphoneos16.2-arm64.xctestrun, rename it to Runner_iphoneos16.6-arm64.xctestrun.Advanced iOS Configuration
Testing on multiple devices
Testing on multiple devices
Test on multiple iOS devices in parallel:
Automated script
Automated script
Create a shell script for iOS testing:Make it executable:See the Patrol example app’s script for more examples.
run_ios_testlab.sh
Available Devices
To see all available devices and OS versions:Best Practices
Use Test Orchestrator
Always use
--use-orchestrator on Android to ensure tests run in isolation and don’t affect each other.Clear Package Data
Set
clearPackageData=true to ensure a clean state between test runs. Note this only clears your app’s data, not system data.Record Videos
Enable
--record-video to capture test execution for debugging failures.Set Timeouts
Use reasonable
--timeout values to avoid hanging tests consuming resources unnecessarily.Troubleshooting
Tests timeout or don't start
Tests timeout or don't start
- Verify both APKs/apps were built correctly
- Check that the device model and OS version are available
- Increase the
--timeoutvalue - Check the Firebase Console logs for detailed error messages
iOS .xctestrun version mismatch
iOS .xctestrun version mismatch
If you see errors about incompatible iOS versions, rename your
.xctestrun file to match the target device’s iOS version:Permission denied errors
Permission denied errors
Make sure you’re authenticated with gcloud:And verify your project is set correctly:
Next Steps
CI/CD Integration
Learn how to integrate Firebase Test Lab into your CI/CD pipeline
BrowserStack
Explore alternative cloud testing platforms