CircleCi 2.0上是否提供Android Espresso的仪器测试?

时间:2018-03-19 13:56:21

标签: circleci android-espresso circleci-2.0

CircleCI 2.0上是否提供针对Android Espresso的Instrumentation测试? 如果是的话,有人可以帮忙为我配置config.yml文件吗? 我做了一千次尝试而没有运气。我可以运行单元测试,但不能运行仪表。

由于

2 个答案:

答案 0 :(得分:1)

这个问题的答案是:是的。 CircleCi可以进行仪器测试。这是我的配置:

version: 2
jobs:
  build:
    working_directory: ~/code
    docker:
        - image: circleci/android:api-25-alpha
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
          name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. 
          command: sudo chmod +x ./gradlew
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
          name: Setup emulator
          command: sdkmanager "system-images;android-25;google_apis;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-25;google_apis;armeabi-v7a"
      - run:
          name: Launch emulator
          command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on
          background: true
      - run:
          name: Wait emulator
          command: |
            # wait for it to have booted
            circle-android wait-for-boot
            # unlock the emulator screen
            sleep 30
            adb shell input keyevent 82
      - run:
          name: Run Tests
          command: ./gradlew connectedAndroidTest
      - store_artifacts:
          path: app/build/reports
          destination: reports
      - store_test_results:
          path: app/build/test-results

此配置的唯一问题是,由于内存错误不足,导致无法成功构建。如果有人有更好的配置,请分享。

答案 1 :(得分:1)

我正在CircleCI MacOS执行程序上运行Android UI测试。 这是我的配置:

version: 2
reference:
  ## Constants
  gradle_cache_path: &gradle_cache_path
    gradle_cache-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
  workspace: &workspace
    ~/src
  ## Configurations
  android_config: &android_config
    working_directory: *workspace
    macos:
      xcode: "9.4.0"
    shell: /bin/bash --login -eo pipefail
    environment:
      TERM: dumb
      JVM_OPTS: -Xmx3200m
  ## Cache
  restore_gradle_cache: &restore_gradle_cache
    restore_cache:
      key: *gradle_cache_path
  save_gradle_cache: &save_gradle_cache
    save_cache:
      key: *gradle_cache_path
      paths:
        - ~/.gradle

  ## Dependency Downloads
  download_android_dependencies: &download_android_dependencies
    run:
      name: Download Android Dependencies
      command: ./gradlew androidDependencies

jobs:
  ui_test:
    <<: *android_config
    steps:
      - checkout
      - run:
          name: Setup environment variables
          command: |
            echo 'export PATH="$PATH:/usr/local/opt/node@8/bin:${HOME}/.yarn/bin:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin:/usr/local/share/android-sdk/tools/bin"' >> $BASH_ENV
            echo 'export ANDROID_HOME="/usr/local/share/android-sdk"' >> $BASH_ENV
            echo 'export ANDROID_SDK_HOME="/usr/local/share/android-sdk"' >> $BASH_ENV
            echo 'export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"' >> $BASH_ENV
            echo 'export QEMU_AUDIO_DRV=none' >> $BASH_ENV
            echo 'export JAVA_HOME=/Library/Java/Home' >> $BASH_ENV
      - run:
          name: Install Android sdk
          command: |
            HOMEBREW_NO_AUTO_UPDATE=1 brew tap homebrew/cask
            HOMEBREW_NO_AUTO_UPDATE=1 brew cask install android-sdk
      - run:
          name: Install emulator dependencies
          command: (yes | sdkmanager "platform-tools" "platforms;android-26" "extras;intel;Hardware_Accelerated_Execution_Manager" "build-tools;26.0.0" "system-images;android-26;google_apis;x86" "emulator" --verbose) || true
      - *restore_gradle_cache
      - *download_android_dependencies
      - *save_gradle_cache
      - run: avdmanager create avd -n Pixel_2_API_26 -k "system-images;android-26;google_apis;x86" -g google_apis -d "Nexus 5"
      - run:
          name: Run emulator in background
          command: /usr/local/share/android-sdk/tools/emulator @Pixel_2_API_26 -skin 1080x2066 -memory 2048 -noaudio
          background: true
      - run:
          name: Run Tests
          command: ./gradlew app:connectedAndroidTest

https://gist.github.com/DoguD/58b4b86a5d892130af84074078581b87

我希望对您有帮助