Running Flutter Tests for Android
Android tests are run on the Linux operating system. A virtual machine (VM) is preconfigured with Flutter (verify the current version using the flutter doctor
command) and Android SDK version 29.0.2.
Create a shell script file named run-tests.sh
that comprises the necessary commands for executing the tests.
Unzip test files:
unzip tests.zip
Accept the SDK licenses:
yes | flutter doctor --android-licenses
Execute the
flutter doctor
command: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 you wish to display test results (a file called
TEST-all.xml
) or screenshots in the cloud UI:Return to the root directory (test result files are located in the root directory):
cd ...
Transfer the file named TEST-all.xml to the root directory:
mv my_app/TEST-all.xml TEST-all.xml
Establish a directory named
screenshots
and relocate the screenshots there (example command):mkdir -p screenshots mv /tmp/screenshots/test/ screenshots
Generate a zip file that includes the run-tests.sh
file and your Flutter project directory. Ensure that the run-tests.sh
file is located in the root of the zip file; otherwise, it won't be detected. Utilize the following sample command to create the zip file: zip -r android-test-files run-tests.sh my_app
. Upload this file to the cloud and designate it as the Use to run the test file.
An Appium Server-Side test project requires the uploading of an APK file. Upload a small sample app file and designate it for installation on the device using the Install on the device option. Ensure that the app can be successfully installed on the device; otherwise, the test will fail. A live Flutter app for testing purposes is built during the test run.
Create a Flutter Android Test Run
To create a Flutter Android test run in BitBar Cloud:
Initiate an Appium Android Server Side 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