Slide 1

Slide 1 text

© 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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

© 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を連携する

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. リリースしたが… なんか私のGalaxy S6(Android 6) でクラッシュするんですが… 弱ったな… こちらで確認できないぞ

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

© 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にアップロードして実⾏

Slide 39

Slide 39 text

© 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にアップロードして実⾏

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

© 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で細かい設定が可能

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

© 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/

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

© 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に通知する

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

© 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/