Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS Device FarmとCircleCIでAndroidのUIテストを自動化しよう

AWS Device FarmとCircleCIでAndroidのUIテストを自動化しよう

AWS Device FarmとCircleCIでAndroidのUIテストを自動化しよう

Fumihiko Shiroyama

December 16, 2019
Tweet

More Decks by Fumihiko Shiroyama

Other Decks in Technology

Transcript

  1. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Application Prototyping Solutions Architect
    Fumihiko Shiroyama
    December 16, 2019
    AWS Device FarmとCircleCIで
    AndroidのUIテストを⾃動化しよう
    Android/iOS Test Night 2019

    View Slide

  2. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    ⾃⼰紹介
    名前:⽩⼭ ⽂彦(しろやま ふみひこ)
    所属:アマゾン ウェブ サービス ジャパン株式会社
    アプリケーションプロトタイピングソリューションアーキテクト
    経歴:インフラエンジニア、バックエンド開発者
    モバイルアプリ開発者、クラウドアーキテクト
    趣味:⼦育て!、懸垂、⾃動テスト#

    View Slide

  3. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    ⾃動テスト⼤好きです!
    • Androidテスト全書という本を出しました
    • ⾃動テストの種類やそれぞれがカバーする範
    囲、モック(テストダブル)の考え⽅、UIテ
    スト、CI/CDとの統合など、Androidにおけ
    るテストについてひと通りカバーされた本で

    View Slide

  4. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    アジェンダ
    本セッションのゴール
    • AWS Device Farmでノーテストでバグを⾒つける
    • AWS Device Farmで任意のバージョンの端末にリモートアクセス
    • AWS Device FarmでUIテストを⾃動実⾏
    • CircleCIからAWS Device Farmを利⽤する
    • CI/CDとSlackを連携する

    View Slide

  5. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    対象となるアプリ

    View Slide

  6. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    ゴリラ
    CHANGE

    View Slide

  7. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    ゴリラ
    CHANGE

    View Slide

  8. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    デモ

    View Slide

  9. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    特定のバージョンのバグを⾒つけ出す

    View Slide

  10. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    リリースしたが…

    なんか私のGalaxy S6(Android 6)
    でクラッシュするんですが…
    弱ったな…
    こちらで確認できないぞ

    View Slide

  11. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    バグの事実と原因を確かめたい
    • ユーザからAndroid 6系で動かないという報告があった
    • 実はAndroid 6以下でクラッシュする深刻なバグがある
    • 報告を確かめたいが古い端末は⼿元にない
    • AWS Device Farmを使ってみよう(

    View Slide

  12. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    AWS Device Farm

    View Slide

  13. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    近年のモバイル開発が抱える課題
    デバイスとOSの
    多様化
    複数のテストフレー
    ムワーク対応の困難
    デバイスメンテ
    の⼿間
    テストレポートの
    可視化に対する要望

    View Slide

  14. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    AWS Device Farm
    ⾃動テスト リモートアクセス
    ⾃動テストを好きな時に
    好きな数だけクラウド上
    で並列実⾏
    クラウド上の好きな端末の
    任意のバージョンですぐに
    リモートで動作確認

    View Slide

  15. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    様々なテストパターンに対応
    アプリ
    UI Automation
    UI Automator
    XCTest
    各種テストフレームワーク AWS Device Farm 詳細なレポート

    View Slide

  16. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    デバイスタイプ
    • パブリックデバイス
    • 0.17USD∕デバイス分の従量課⾦(無料利⽤期間1000デバイス分あり)
    • 250USD∕⽉の定額プランで無制限利⽤
    • 端末はテスト毎にデータ消去して再起動
    • プライベートデバイス
    • 200USD∕⽉から利⽤できる専有デバイス※1※2
    • デバイスは専有で決して他者と共有されず、契約終了後に廃棄
    ※1 端末の取得価格によって変動
    ※2 最低6ヶ⽉の利⽤など諸条件あり

    View Slide

  17. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    早速使ってみよう

    View Slide

  18. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Built-in: Fuzzテスト
    • いわゆるモンキーテスト
    • テストコードがなくてもUIをランダムに操作して落ちないか確認
    • 複数のデバイスやOSを並列実⾏できる

    View Slide

  19. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    apkをビルド
    ./gradlew :app:assembleDebug

    View Slide

  20. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    AWS Device Farm
    プロジェクトの作成

    View Slide

  21. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Automated Tests
    apkのアップロード
    ⾃動テストを選択

    View Slide

  22. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Automated Tests
    テストするデバイス群
    Fuzzテスト
    Device poolの選択

    View Slide

  23. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Fuzzテスト
    テスト結果
    やはり古いバージョンで
    エラーが起こっているようだ

    View Slide

  24. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Fuzzテスト
    テスト結果

    View Slide

  25. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    エラーの録画を確認する

    View Slide

  26. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    正常系

    View Slide

  27. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    異常系

    View Slide

  28. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Screenshots
    正常系
    異常系

    View Slide

  29. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Screenshots
    正常系
    異常系

    View Slide

  30. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Logs

    View Slide

  31. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    リモートアクセス

    View Slide

  32. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    リモートアクセス
    ⽬当ての端末選択
    リモートアクセス

    View Slide

  33. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    リモートアクセス
    ブラウザから操作

    View Slide

  34. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    リモートアクセス
    アップロードして
    実際に試すことができる

    View Slide

  35. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    その他のテスト

    View Slide

  36. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    その他のテストをAWS Device Farmで実⾏する
    • AWS Device FarmはFuzzテスト以外にも多数のテストをサポートしている
    • Instrumentationを選ぶことでUIテスト(Espresso)が実⾏できる
    • 他にもAppiumやUI Automatorなど多数のフレームワークをサポートしている

    View Slide

  37. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Instrumentation (Espresso)

    View Slide

  38. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Instrumentation (Espresso)
    • https://docs.aws.amazon.com/ja_jp/devicefarm/latest/developerguide/test-
    types-android-instrumentation.html
    1. ⼿順を参考にアプリ本体のapkをビルドする(assembleDebug)
    2. ⼿順を参考にUIテストのapkをビルドする(assembleDebugAndroidTest)
    3. AWS Device Farmにアップロードして実⾏

    View Slide

  39. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Instrumentation (Espresso)
    • https://docs.aws.amazon.com/ja_jp/devicefarm/latest/developerguide/test-
    types-android-instrumentation.html
    1. ⼿順を参考にアプリ本体のapkをビルドする(assembleDebug)
    2. ⼿順を参考にUIテストのapkをビルドする(assembleDebugAndroidTest)
    3. AWS Device Farmにアップロードして実⾏

    View Slide

  40. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Instrumentationテスト
    テストapkをアップロード

    View Slide

  41. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Instrumentationテスト
    ⽤途に応じて独⾃のDevice Poolも定義できる
    Deviceの台数や組み合わせも任意

    View Slide

  42. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Instrumentationテスト
    追加のオプションや
    タイムアウトを設定して実⾏

    View Slide

  43. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Instrumentationテスト

    View Slide

  44. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Instrumentationテスト

    View Slide

  45. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CI/CDとの統合

    View Slide

  46. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CI/CDとの統合
    • AWS Device Farmは便利だが⼿動でアップロードは⼤変
    • CI/CDツールと連携することで⽇々のテストを⾃動化できる
    • ここではCircleCIを使ってDevice Farmのテストを⾃動化する
    • https://circleci.com/

    View Slide

  47. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIとの連携
    macOSでビルドするには有料プランが必要(無料トライアルあり)

    View Slide

  48. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIの設定
    • プロジェクト直下に.circleci/config.ymlという設定ファイルを設置
    • yamlファイルを編集しビルドとテストの実⾏を設定(後述)
    • Gitレポジトリへのプッシュを契機にビルドとテストが開始される
    • 基本はGradleのコマンドを記述するだけ

    View Slide

  49. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    aws-device-farm-gradle-plugin
    • https://github.com/awslabs/aws-device-farm-gradle-plugin
    • Gradle plugin for AWS Device Farm
    • apkのビルド、アップロード、テストの実⾏などを⼿助けするプラグイン
    • DSLで細かい設定が可能

    View Slide

  50. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Project build.gradle
    • classpath 'com.amazonaws:aws-devicefarm-gradle-plugin:1.3’

    View Slide

  51. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    App build.gradle
    • apply plugin: 'devicefarm’
    • devicefarm{ 各種設定 }
    • ./gradlew devicefarmUpload
    projectNameは
    Device Farmの設定に合わせる

    View Slide

  52. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    App build.gradle
    • apply plugin: 'devicefarm’
    • devicefarm{ 各種設定 }
    • ./gradlew devicefarmUpload
    IAMユーザと権限は最⼩に!

    View Slide

  53. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIへの組み込み
    • 基本はGradleコマンドを列挙するだけ
    • ./gradlew :app:assembleDebug
    • ./gradlew :app:assembleDebugAndroidTest
    • ./gradlew :app:devicefarmUpload

    View Slide

  54. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIの環境変数設定

    View Slide

  55. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIの環境変数設定

    View Slide

  56. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    • https://slack.com/services/new/incoming-webhook
    Slackに通知

    View Slide

  57. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIの環境変数設定

    View Slide

  58. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Slackに通知

    View Slide

  59. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    満を持してプッシュ!

    View Slide

  60. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIコンソール

    View Slide

  61. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIコンソール

    View Slide

  62. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Device Farmコンソール

    View Slide

  63. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCI Workflow
    • すべてのプッシュでDevice Farm連携したくないケース
    • Workflow機能を使ってmaster/releaseブランチプッシュ時だけ
    Device FarmでUIテストを実⾏するといった制御が可能
    • https://circleci.com/docs/ja/2.0/workflows/

    View Slide

  64. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    View Slide

  65. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

    View Slide

  66. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    処理の流れおさらい
    1. Gitレポジトリへのプッシュを契機にCircleCIでビルドが始まる
    2. 通常のGradleコマンドでapkをビルド
    3. ワークフローでmasterブランチだけDevice Farmが⾛る
    4. aws-device-farm-gradle-pluginプラグインがDevice Farmにアップロード
    5. 結果をCircleCIに通知する

    View Slide

  67. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    CircleCIコンソール
    masterだけ
    UIテスト

    View Slide

  68. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Yay!!!

    View Slide

  69. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    ご清聴ありがとございました,

    View Slide

  70. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    質疑応答

    View Slide

  71. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    Appendix

    View Slide

  72. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    スライドURL
    http://bit.ly/34iYRc4

    View Slide

  73. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
    AWS Device Farm テストデバイス⼀覧
    • Q. AWS Device Farmではどのようなデバイスが利⽤できますか
    • A. モバイルアプリケーションのテストに使⽤できる iOS、Android、
    および Fire OS の実機は増え続けています。デバイス群は、市場の
    データとお客様からのフィードバックをもとに、今後も引き続き更
    新していく予定です。⼀覧は次のリストをご覧ください。
    • http://awsdevicefarm.info/

    View Slide