Does Your Company Need QA Transformation? Here Are the Warning Signs!
In the dynamic landscape of software development, ensuring the highest level of quality
Testing across all interfaces, platforms and architectural components
Product test engineering, Shift-Left testing and digital transformation
Automate tests across all interfaces, platforms and horizontal scaling
Generative AI, Flutter, React Native, Micro-services, Micro-frontends & TestOps
Measure and enhance the efficiency & effectiveness of testing teams & solutions
Offshore Testing Setup as a Service, platform engineering and Modernisation
Google Firebase Test Lab Integration For iOS Flutter Integration Testing
In this article, we will explore how to integrate our tests with Firebase Test Lab to run on iOS devices. We will provide a step-by-step guide on how to create a shell script that automates our test cases and runs them on Test Lab for iOS, with a detailed analysis of the resulting reports.
You need to locate the name of your bundleId, which can be found in “ios/Runner.xcodeproj/project.pbxproj”. In case you are unsure, I would recommend seeking assistance from a developer.
Open ios/Runner.xcworkspace
in Xcode. Create a test target via File > New > Target.
Select Unit Testing Bundle
. Change the Product Name
to RunnerTests
Select Target to be Tested
is set to Runner
and language is set to Objective-C
. Update Orginization Identifier
as bundle ID which we identified in Step 1.
The above step will create ios/RunnerTests/RunnerTests.m file.
Update the file with the –
@import XCTest;
@import integration_test;
INTEGRATION_TEST_IOS_RUNNER(RunnerTests)
Update your ios/Podfile file target ‘Runner‘ with –
target 'Runner' do
use_frameworks!
use_modular_headers!
target 'RunnerTests' do
inherit! :search_paths
end
end
If you get any Error on the ios/RunnerTest/RunnerTest.m file. Make sure to install the pods again. Run the commands –
cd ios
pod deintegrate
pod install --repo-update
To make sure the setup is correct, Run the test from Xcode. It will launch the simulator and run the tests.
We will create one LocalRunner shell file to make sure, we are all good to run our tests on IOS from the command line.
Our local runner file will look like this –
flutter build ios integration_test/tests/create_todo_test.dart --release
pushd ios
xcodebuild -workspace Runner.xcworkspace -config Release -derivedDataPath ../build/ios_integ -sdk iphoneos build-for-testing
popd
# To Run Test In Local
xcodebuild test-without-building \
-xctestrun "build/ios_integ/Build/Products/dev_iphoneos16.2-arm64.xctestrun" \
-destination 'platform=iOS Simulator,name=iPhone 14 Pro Max'
Now we will look into the details of each step in the above file.
To build an iOS IPA file that points to our tests, we will use the following command –
flutter build ios integration_test/tests/create_todo_test.dart --release
The way we run our tests from Xcode, we have to do it via CMD. Xcode internally builds the app and then runs the tests. same we will do, first we will combine the IPA with resources.
Ensure that you are in the “ios” folder and use the command –
xcodebuild -workspace Runner.xcworkspace -config Release -derivedDataPath ../build/ios_integ -sdk iphoneos build-for-testing
Once you run the above command, a folder will be generated at “build/ios_integ/Build/Products” containing the IPA product resources. The name of the test runner will be “Runner_iphoneos$dev_target-arm64.xctestrun”, where the value of “dev_target” may vary based on the Xcode version.
For the latest version, it is 16.4, so the runner file name would be “Runner_iphoneos16.4-arm64.xctestrun”.
dev_target=16.4
Now, we need to zip the product and test runner.
pushd build/ios_integ/Build/Products
zip -r "ios_tests.zip" Release-iphoneos Runner_iphoneos16.2-arm64.xctestrun
popd
We will create an authentication key in Firebase. Firstly, we need to log in to our gCloud account and select the Service account. Then, we will be presented with the option to perform actions on the “firebase-adminsdk” account.
Select the “Manage Key” option and proceed to create a new key. You should store this key in your local system, and you will be given the option to save it in JSON format.
We will be setting up gCloud and uploading the zip to Firebase Test Lab. We will be writing a script to authenticate gCloud and perform the upload process. Each step in this process will be explained in detail.
gcloud auth activate-service-account --key-file=gcloud_key_file.json
gcloud --quiet config set project
gcloud firebase test ios run \
--test "build/ios_integ/Build/Products/ios_tests.zip" \
--device=model=iphone11pro,version=16.2
Let’s understand the meaning of each step –
gcloud auth activate-service-account --key-file=
This step will authenticate your system using the downloaded credential keys. We will explain how to store these keys when running on GitHub or Codemagic to ensure security in the upcoming blog post. For now, we will be storing the keys locally in this blog post.
gcloud --quiet config set project
In our local system, we might have authenticated multiple projects for the same gcloud accounts. The previous step will set the project at runtime for which you want to run the tests.
gcloud firebase test ios run \
--test "build/ios_integ/Build/Products/ios_tests.zip" \
--device=model=iphone11pro,version=16.2
This step will upload the zip test to Firebase Test Lab for IOS tests.
Now that we have combined all the steps, our runner file will look like the following, and it will be responsible for running tests on Firebase Test Lab.
output="../build/ios_integ"
product="build/ios_integ/Build/Products"
dev_target="16.2"
PRODUCT_NAME="Release-iphoneos"
TEST_RUNNER="iphoneos$dev_target-arm64.xctestrun"
flutter build ios integration_test/tests/create_todo_test.dart --release
pushd ios
xcodebuild -workspace Runner.xcworkspace -config Release -derivedDataPath $output -sdk iphoneos build-for-testing
popd
pushd $product
zip -r "ios_tests.zip" $PRODUCT_NAME $TEST_RUNNER
popd
gcloud firebase test ios run \
--test "build/ios_integ/Build/Products/ios_tests.zip" \
--device=model=iphone11pro,version=16.2
After running the runner.sh file, it will upload the tests to Firebase Test Lab, and the results will be displayed on the test lab.
In the screenshot above, we can see that our product was uploaded, the tests were run, and a summary of the results was provided. If you click on the link provided at the bottom that says “More details available at…”, it will redirect you to the Firebase Test Lab results page.
Congratulations! You are all good to run tests on the Firebase test lab for IOS.
In the dynamic landscape of software development, ensuring the highest level of quality
Rapid Test Development Platform meets Next-Generation Mobile Apps and Cross Browser Testing Cloud
Share This Article