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 that comprises the necessary commands for executing the tests.

  1. Unzip test files:

  2. Accept the SDK licenses:

    yes | flutter doctor --android-licenses
  3. Execute the flutter doctor command:

    flutter doctor
  4. (Optional) Go to the Flutter project directory (sample command):

    cd my_app
  5. (Optional) Clean the project folder (build/packages):

    flutter clean
    rm -r .packages
    rm pubspec.lock
  6. Run Flutter integration tests (sample command):

    flutter drive --target=test_driver/main.dart
  7. (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 file and your Flutter project directory. Ensure that the 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 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:

  1. Initiate an Appium Android Server Side test run.

    Select Android Target OS Type
    Select Flutter Framework
  2. 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.

    Choose Android Test Files
  3. Select devices.

  4. Set a test timeout period. Make sure it is long enough.

  5. Run tests.

A Simplified Example for Android Integration Tests

Here is an example of a complete file for an Android integration test with minimal content.

yes | flutter doctor --android-licenses
cd flutter_app
flutter clean
rm -r .packages
rm pubspec.lock
flutter drive --target=test_driver/main.dart

See Also

Publication date: