Last modified on October 21, 2020

iOS simulator

iOS simulator test runs spend actual real device test time, the real iOS device is just idling while the simulator is running tests. iOS tests are run on the Mac OS. Flutter is preinstalled on virtual machines. Cocoapods need to be installed, it can be done using the run-tests.sh file.

Create a shell script file called run-tests.sh. This file will contain commands to execute the test.

  1. Unzip test files:

    unzip tests.zip

  2. Install cocoapods:

    sudo gem install cocoapods
    pod setup

  3. Run Flutter doctor:

    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. Install an iOS simulator:

    npm install -g ios-sim

  7. Start the simulator:

    ios-sim start --devicetypeid "iPhone-8"

  8. Find the simulator device from Flutter devices:

    flutter devices > devices.txt
    cat devices.txt | while read line
    do
    case "$line" in
    *simulator*)
      TEST_DEVICE=$line
      RUN_DEVICE=`echo ${TEST_DEVICE} | awk '{print $1, $2}'`
      echo $RUN_DEVICE > run_device.txt
      echo "device"
      cat run_device.txt
      ;;
      *)
      ;;
    esac
    done

  9. Run Flutter integration tests using the simulator (sample command):

    flutter drive -d "`cat run_device.txt`" --target=test_driver/main.dart

  10. (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 the 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 ios-test-files run-tests.sh my_app. Upload this file to the cloud and use it as the “Use to run the test” file.

Create a Flutter iOS simulator test run

To create a Flutter iOS simulator test run in BitBar Cloud:

  1. Create a Appium iOS Server Side-type test run.

    iOS test run
    Appium iOS Server Side test run
  2. Upload the test zip file and the actual app .ipa file or a small sample app .ipa file (it needs to be able to get installed to the actual real iOS device, no simulator builds), the test does not use this app.

    Uploading files

    Click the image to enlarge it.

  3. Select devices (the actually selected device is not used to run tests on).

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

  5. Run tests.

iOS real device

iOS real device testing is not guaranteed to work because of iOS app signing (no proper documentation from Flutter is yet available).

An iOS Flutter app needs to be built locally, and then the Runner app (converted to a .ipa file) will need to be uploaded to the cloud (as “Install on the device”). The Runner .ipa file is then re-signed in the cloud. During the test run, the app will need to be moved to the build/ios/iphoneos/ directory. The test is then run using the –no-build -flag. Currently, 32 bit iOS devices and iOS 13 devices don’t work with Flutter in BitBar Cloud. Read more about how to create .ipa from .app.

Create a shell script file called run-tests.sh. This file will contain commands to execute the test.

  1. Unzip test files:

    unzip tests.zip

  2. Install cocoapods:

    sudo gem install cocoapods
    pod setup

  3. Run Flutter doctor:

    flutter doctor

  4. Unzip the re-signed Flutter iOS app (it will be called “application.ipa”):

    mv application.ipa application.zip
    unzip application.zip

  5. Get rid of the “Payload” directory:

    mv Payload/Runner.app Runner.app

  6. Move the Runner app to the build directory (create a build directory if it is not already in the project directory)(sample command):

    mv Runner.app my_app/build/ios/iphoneos/Runner.app

  7. (Optional.) Go to the Flutter project directory (sample command):

    cd my_app

  8. Run Flutter integration tests without building the app (sample command):

    flutter drive -v --no-build --target=test_driver/main.dart

  9. (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 the 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 ios-test-files run-tests.sh my_app. Upload this file to the cloud and use it as the “Use to run the test” file.

Create a Flutter iOS real device test run

To create a Flutter iOS real device test run in BitBar Cloud:

  1. Create an Appium iOS Server Side-type test run.

    iOS test run
    Appium iOS Server Side test run
  2. Upload a test zip file and the actual app file (Runner.app ) from the build/ios/iphoneos/ -directory converted to an .ipa file.

    Uploading files

    Click the image to enlarge it.

  3. Select devices (the actually selected device is not used to run tests on).

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

  5. Run tests.

See Also

Flutter Support

Highlight search results