LoginSignup
13
12

More than 5 years have passed since last update.

CI環境でFirebase Test Lab for iOSの実機テストを自動化する

Last updated at Posted at 2019-04-12

CI環境でiOS版Firebase Test Labの自動化をする手順をまとめました。
Bitrise前提で書いてますが、gcloudコマンドを使っているのでどのCI環境でも応用できます。

【前提】Test Lab for iOSで出来ること

Google データセンターでホストされているデバイス上で実機Unit Test, UI Testが可能。
AndroidでサポートされているRobo テストはiOSではサポートされてないが、手動だと辛い複数端末テストがクラウド上で出来るだけでも便利。

results2.png

動画でテストの実行内容を確認可能

test_movie.png

理解を深めるには、公式リファレンスに載ってる通り

  1. XCTestの.zipファイルをコンソールに上げる方法で試す
  2. gcloudコマンドでテスト実行
  3. CI上でgcloudコマンドでテスト実行

の手順で進めると良い

gcloudコマンドでテストを自動化する

CLIでテストを実行するには、GCPのコマンドラインツールである gcloudコマンドを使う

手順

  1. gcloudコマンドのインストール(プリインストールされている環境なら不要)
  2. gcloud authコマンドでGCPのサービスアカウントキーを使った認証を行う
  3. gcloud configコマンドでFirebaseのproject idを紐付ける
  4. テスト実行

Script全体はこんな感じ

#!/bin/bash
set -ex

# install gcloud
curl https://sdk.cloud.google.com | bash 
source $HOME/google-cloud-sdk/path.bash.inc

# setup project
curl -o /tmp/sacc_key.json $BITRISEIO_SERVICE_ACCOUNT_KEY_URL
gcloud auth activate-service-account -q --key-file /tmp/sacc_key.json
gcloud config set project $FIREBASE_PROJECT_ID

# run test
gcloud firebase test ios run --test "${BITRISE_TEST_BUNDLE_ZIP_PATH}" \
  --device model=iphone8,version=11.4,locale=ja_JP \
  --device model=iphonex,version=12.0,locale=ja_JP \
  --device model=iphonexsmax,version=12.1,locale=ja_JP \
  --device model=iphonese,version=11.4,locale=ja_JP

補足1: 認証

Firebaseのドキュメントに書いてあるGoogleアカウントを使ったOAuth認証の他、GCPのサービスアカウントキーを使った認証も可能。

curl -o /tmp/sacc_key.json $BITRISEIO_SERVICE_ACCOUNT_KEY_URL
GCPのサービスアカウントキー(JSONファイル)をBitrise上にアップロードして、そのURLからキーをDLして認証している
Bitriseの場合、[Code Signing] > [GENERIC FILE STORAGE]タブ からアップロードが可能。URLを示す環境変数が生成される
※Code Signingタブのセキュリティについてはこちら

補足2: テスト実行

"${BITRISE_TEST_BUNDLE_ZIP_PATH}"
Bitriseのステップ [BETA] Xcode Build for testing for iOS を使って生成したテスト .zipファイルのpathを指定している

Bitriseを使っている場合

iOS Device Testing ステップを使えば簡単にTest Labを使ったテスト実行と確認が可能(全部実装し終わった後に知った。)
https://devcenter.bitrise.io/testing/device-testing-for-ios/

test-results

参考URL

https://discuss.bitrise.io/t/how-to-run-android-tests-on-firebase-testlab/2192
https://swet.dena.com/entry/2018/12/02/000000

13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12