Running Flutter tests for Android
Android tests are run on the Linux OS. Flutter (check the current version with the flutter doctor
command) and Android SDK version 29.0.2 are preinstalled on a VM machine.
Create a shell script file called run-tests.sh
. This file will contain commands to execute the test.
Unzip test files:
unzip tests.zip
Accept SDK licenses:
yes | flutter doctor --android-licenses
Run Flutter doctor:
flutter doctor
(Optional.) Go to the Flutter project directory (sample command):
cd my_app
(Optional.) Clean the project folder (build/packages):
flutter clean rm -r .packages rm pubspec.lock
Run Flutter integration tests (sample command):
flutter drive --target=test_driver/main.dart
(Optional.) If test results (a file called TEST-all.xml) or screenshots should be displayed in the cloud UI:
Go back to the root directory (test result files are searched in the root directory):
cd ...
Move “TEST-all.xml” to the root directory:
mv my_app/TEST-all.xml TEST-all.xml
Create a “screenshots” directory and move screenshots there (sample command):
mkdir -p screenshots mv /tmp/screenshots/test/ screenshots
Create a zip file containing the run-tests.sh
file and your Flutter project directory. Note that the “run-tests.sh” file must be in the root of the zip file, otherwise, it is not found. Here is a sample command to create a zip file: zip -r android-test-files run-tests.sh my_app
. Upload this file to the cloud and use it as the “Use to run the test” file.
An Appium Server Side-type test project expects an APK file to be uploaded. Upload a small sample app file and use it as “Install on the device”. Note that the app needs to be able to get installed to the device, otherwise, the test will fail. An Actual Flutter app to test is built during the test run.
Create a Flutter Android test run
To create a Flutter Android test run in BitBar Cloud:
Create an Appium Android Server Side -type test run.
Upload the test zip file and the actual app APK file or a small sample app APK file (the app needs to be able to get installed to the device), the test does not use this app.
Select devices.
Set a test timeout period. Make sure it is long enough.
Run tests.
A simplified run-tests.sh example for Android integration tests
Here is an example of a complete run-tests.sh
file for an Android integration test with minimal content.
unzip tests.zip yes | flutter doctor --android-licenses cd flutter_app flutter clean rm -r .packages rm pubspec.lock flutter drive --target=test_driver/main.dart