Run your flutter integration tests on BrowserStack. You can Refer to this link, if you are new to flutter
Check the pubspec.yaml file and make sure you have added those dependencies
- A sample app code is present inside the lib folder so that you can test it.
- You can run the app locally from the command line as follows:
flutter run
- Integration tests are present inside the integration_test folder.
integration_test/app_test.dart
- For running the test locally:
flutter test integration_test/app_test.dart
- Create an instrumentation test file in android/app/src/androidTest/java/com/example/flutter_native/MainActivityTest.java
- Update flutter_native/android/app/build.gradle file to make sure it uses androidx's version of AndroidJUnitRunner and has androidx libraries as a dependency.
android { ... defaultConfig { ... testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } } dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' }
- Use the following Gradle commands to build an instrumentation test.apk file(test suite) using the MainActivityTest.java created in the androidTest directory
pushd android
flutter build apk
./gradlew app:assembleAndroidTest
If you encounter the error "gradle:compileGroovy FAILED," please refer to the resolution provided at the end of the Android section../gradlew app:assembleDebug -Ptarget=`pwd`/../integration_test/app_test.dart
popd
- App APK:
build/app/outputs/apk/debug/app-debug.apk
- Test Suite APK:
build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk
curl -u "BROWSERSTACK_USERNAME:BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/flutter-integration-tests/v2/android/app" \
-F "file=@/path/to/app/file/Application-debug.apk"
Note down the app_url from the response
curl -u "BROWSERSTACK_USERNAME:BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/flutter-integration-tests/v2/android/test-suite" \
-F "file=@/path/to/app/file/Application-debug-test.apk"
Note down the test_suite_url from the response
curl -u "BROWSERSTACK_USERNAME:BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/flutter-integration-tests/v2/android/build" \
-d '{"app": "<APP_URL>", "testSuite": "<TEST_SUITE_URL>", "devices": ["Samsung Galaxy S21-12.0"]}' \
-H "Content-Type: application/json"
- Run the following command to find your Java version:
java --version
- Visit this link and identify the Gradle version compatible with your Java version. For example, if your Java version is 22.0, the matching Gradle version is 8.8
- Navigate to your project folder and locate the gradle-wrapper.properties file in:
android/gradle/wrapper/gradle-wrapper.properties.
Update the distributionUrl version:
Current value:
distributionUrl=https://services.gradle.org/distributions/gradle-8.3-all.zip
Update to:distributionUrl=https://services.gradle.org/distributions/gradle-8.8-all.zip
- Run your project again. Gradle will automatically download the updated version.
- On Xcode, open
ios/Runner.xcworkspace
in your app’s iOS folder. - Ensure that the
iOS Deployment Target
setting in the Build Settings section for the RunnerTests file matches the setting in the Runner file. - Add a test file
RunnerTests.m
to aRunnerTests
target file in Xcode. - Execute the following commands:
output="../build/ios_integration"
product="build/ios_integration/Build/Products"
flutter build ios integration_test/app_test.dart --release
If you encounter the error "module 'integration_test' not found" please refer to the resolution provided at the end of the IOS section.pushd ios
xcodebuild -workspace Runner.xcworkspace -scheme Runner -config Flutter/Release.xcconfig -derivedDataPath $output -sdk iphoneos build-for-testing
popd
pushd $product
zip -r "com.khunsha.flutterNative.zip" "Release-iphoneos" "Runner_iphoneos16.4-arm64.xctestrun"
xctestrun file is present at the build output path build/ios_integration/Build/Products.popd
- zip file:
build/ios_integration/Build/Products/com.khunsha.flutterNative.zip
curl -u "BROWSERSTACK_USERNAME:BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/flutter-integration-tests/v2/android/app" \
-F "file=@/path/to/your/ios/test/package.zip"
Note down the test_package_url from the response
curl -u "BROWSERSTACK_USERNAME:BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/flutter-integration-tests/v2/android/build" \
-d '{"devices": ["iPhone 14-18"], "testPackage":"<TEST_PACKAGE_URL>","networkLogs":"true","deviceLogs":"true"}' \
-H "Content-Type: application/json"
Follow these steps to resolve the issue:
-
Set the Build Configuration to Release
-
Run the Following Commands (if the above step does not resolve the issue):
flutter pub get cd ios rm -rf Pods/ Podfile.lock pod install
- Run the following command:
sudo arch -x86_64 gem install ffi
- Navigate to the ios folder and run:
arch -x86_64 pod install