How to run Espresso UI tests in Azure devops pipeline

Viewed 696

I've been reading posts and I ended up with a *.yaml that works but looks like is taking way too long because I've tried it with more or less 5 or 6 tests, locally it needs 4 seconds to pass and when I launch the pipeline it takes ~12 min and I'd like to know if I missing something about caching, or I could make it faster.

Note: That I'm also running the UI tests of one feature of the app, thinking this is faster than if I run all the Instrumental tests of the app I'm using this bash to do so :

  • bash: | ./gradlew :features-login:connectedAndroidTest --console=plain --stacktrace ./gradlew --stop
trigger:
  - develop

pool:
  vmImage: 'macos-latest'

jobs:
  - job: Phase_1
    timeoutInMinutes: 25
    displayName: Run Instrumented Tests and publish results
    condition: succeeded()
    pool:
      vmImage: 'macos-latest'
    steps:
      - task: Cache@2
        displayName: 'Caching System Images for AVD'
        inputs:
          key: 'AVD_IMAGES_PIXEL_28'
          path: '$(ANDROID_HOME)/system-images'
          cacheHitVar: 'AVD_IMAGES_RESTORED'
        continueOnError: true
        condition: succeededOrFailed()
      - bash: |
          echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-28;google_apis;x86'
        displayName: 'Download and install emulator image'
        condition: ne(variables.AVD_IMAGES_RESTORED, 'true')
      - bash: |
          echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n android_emulator -k 'system-images;android-28;google_apis;x86' -d 17 --force
          echo "Emulator created successfully $(ANDROID_HOME/emulator/emulator -list-avds), launching it"
          nohup $ANDROID_HOME/emulator/emulator -avd android_emulator -skin 1080x1920 -no-snapshot -no-audio -no-boot-anim -accel auto -gpu auto -qemu -lcd-density 420 > /dev/null 2>&1 &
          $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done'
          $ANDROID_HOME/platform-tools/adb devices
          echo "Emulator started"
        displayName: 'Create and start emulator'
      - bash: |
          ./gradlew :features-login:connectedAndroidTest --console=plain  --stacktrace
          ./gradlew --stop
        displayName: 'Run Instrumented Tests'
        continueOnError: true
      - task: PublishTestResults@2
        displayName: 'Publish Test Results'
        inputs:
          testResultsFiles: '**/outputs/androidTest-results/**/TEST*.xml'
          failTaskOnFailedTests: true
          testRunTitle: 'Test results'
        condition: succeededOrFailed()

Is something I could do in parallel to make the pipeline faster?

_Note: Using this macos-latest is giving me a warning about :

enter image description here

Is there any way to run it on Ubuntu to avoid this warning? I've tried it but it crashes with these errors :

enter image description here

And sometimes after the first successful run it works, but then randomly crashes when trying to run again without touching any code. Could be something about the configuration of the yml? About Cache, or something? It's weird because all the tests fails, not just one or two (could be a flaky tests then, but doesn't seem like that...)

Also when I run the command ./gradlew :features-login:connectedAndroidTest --console=plain --stacktrace It compiles all the project and I thought if I'd put the feature it self it only would compile my feature not all the project.

1 Answers

The SDKManager seem to require Java 8 to function properly on Azure Devops. If you add

    env:
      JAVA_HOME: $(JAVA_HOME_8_X64)
      PATH: $(JAVA_HOME_8_X64)/bin:$(PATH)

to your $ANDROID_HOME/tools/bin/avdmanager create avd task it will start run properly.

Related