Android Instrumentation测试在Travis CI AVD上失败,但在本地模拟器上工作

SoH*_*SoH 8 instrumentation android android-virtual-device travis-ci

如果我在我的本地模拟器上运行仪器测试,它们完美地运行10次,但是当我尝试在Travis CI中的AVD上运行相同的测试时,我随机获得

FAILED java.lang.RuntimeException: Could not launch intent Intent { } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was xxxxxxx and now the last time the queue went idle was: xxxxxxxxx. If these numbers are the same your activity might be hogging the event queue.

我已经尝试删除所有进度条和一切,但仍然是一个只在Travis上随机发生的问题.我的travis.yml看起来像这样:

env:
  global:
    - ANDROID_TARGET=android-19
    - ANDROID_ABI=armeabi-v7a
  before_script:
      - android list targets
      - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
      - emulator -avd test -no-skin -no-audio -no-window -no-boot-anim &
      - android-wait-for-emulator
      - adb shell input keyevent 82 &
    script:
      - ./gradlew jacocoTestReport assembleAndroidTest connectedCheck zipalignRelease
Run Code Online (Sandbox Code Playgroud)

alb*_*elu 0

如果您想使用android-wait-for-emulator脚本,请删除-no-boot-anim它所依赖的用于检测模拟器何时准备就绪的选项。

或者,将android-wait-for-emulator脚本替换为固定的睡眠时间,如下所示:

  - sleep 300
  - adb shell input keyevent 82 &
Run Code Online (Sandbox Code Playgroud)

您需要根据每个 API 启动时长选择睡眠时间。