Run your Flutter integration tests for iOS
Integration tests are used to test how individual code works together and to capture the overall performance of an app. The integration_test package, provided by Flutter, is used to write integration tests for your Flutter app.
In this guide, you’ll learn how to:
- Setup BrowserStack account
- Prepare iOS Flutter test package for testing
- Upload your test package
- Run iOS Flutter integration tests
Prerequisites
- You must use Xcode to create and publish your app.
- Ensure that your application complies with Apple’s Review Guideline before starting the release process.
Setup BrowserStack account
You will need a BrowserStack username
and access key
. To obtain your access credentials, sign up for a free trial or purchase a plan.
Prepare iOS Flutter test package for testing
- Launch the Xcode Application.
- Open
ios/Runner.xcworkspace
in your app’s iOS folder on Xcode. - Click
File > New > Target
. - Create a new Target by clicking on Unit Testing Bundle under the Test Section in the Target window.
- Rename the Product Name to
RunnerTests
in the Target window. Set the Target to be Tested toRunner
and set the languageObjective-C
.
Note: Ensure that the iOS Deployment Target ofRunnerTests
file within the Build Settings section is the same asRunner
file. - Add a test file
RunnerTests.m
to a new target file in Xcode. This file acts as the entry point for your tests and executes the flutter wrapper. Add the following code snippet to the file:@import XCTest; @import integration_test; INTEGRATION_TEST_IOS_RUNNER(RunnerTests)
- Add the new test target to
ios/Podfile
by embedding it in the existingRunner
target.target 'Runner' do #Do not change existing lines. ... target 'RunnerTests' do inherit! :search_paths end end
- Run the following command to build
<file_name>.dart
:flutter build ios <file_name>.dart --release
- Execute the following script at the root of your Flutter app:
output="../build/ios_integration" product="build/ios_integration/Build/Products" dev_target="<target-name>" # Pass --simulator if building for the simulator. flutter build ios integration_test/<file_name>.dart --release pushd ios xcodebuild -workspace Runner.xcworkspace -scheme Runner -config Flutter/Release.xcconfig -derivedDataPath $output -sdk iphoneos build-for-testing popd pushd $product zip -r "<ios_test_package_name>.zip" "Release-iphoneos" "Runner_iphoneos$dev_target-arm64.xctestrun" popd
Verify locally that your tests are successful by running the following command:
xcodebuild test-without-building -xctestrun "build/ios_integration/Build/Products/Runner_iphoneos$dev_target-arm64.xctestrun" -destination id=<DEVICE_ID>
Upload your test package
Upload your iOS app test package (<ios_test_package_name>
in step 9) in .zip
format to BrowserStack servers using the REST API request.
The following sample cURL
command shows how to upload the test package:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY"
-X POST "https://api-cloud.browserstack.com/app-automate/flutter-integration-tests/v2/ios/test-package"
-F "file=@path/to/your/ios/test/package.zip"
A sample response for the above request is as follows:
{
"test_package_name":"<ios_test_package_name>.zip",
"test_package_url":"bs://3f8ca850476a7c26d4698225e32b353c83cac7ed",
"test_package_id":"3f8ca850476a7c26d4698225e32b353c83cac7ed",
"uploaded_at":"2022-07-21 14:55:59 UTC",
"expiry":"2022-08-20 14:55:59 UTC",
"framework":"flutter-integration-tests",
}
The value of the test_package_url
parameter in the response is used to specify the application under test when you run your package.
Run iOS Flutter integration tests
After you upload your test package to BrowserStack servers, send an API request to start the test execution as shown in the following sample cURL
request:
A sample response for the request is as follows:
{
"message": "Success",
"build_id": "f6f6d4214ebc3ccab9814d8090f5838644b0dc72"
}
The build_id
is used to uniquely identify your build in App Automate.
View test results
After you start Flutter integration tests execution using the REST API, visit your App Automate dashboard to view your test results, debugging logs, and overall test details.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!