Copyright © DeNA Co.,Ltd. All Rights Reserved.
iOS Test Night #4
2017/05/22(Mon)
平田敏之@DeNA
UIテストの実行時間の短縮の方法
- test-without-building / bluepill / pxctest / Pomeranian -
Copyright © DeNA Co.,Ltd. All Rights Reserved.
自己紹介
 平田 敏之@DeNA
⁃ SWET (Software Engineer in Test)
• 事業サポートチーム / テスト基盤チーム
• ミッション
⁃ DeNAサービス全般の品質向上
⁃ DeNAエンジニアの開発生産性向上
⁃ 私がやっていること(の一部)
• クライアントアプリ周りのテスト戦略、自動テストの開発
• CI/CD環境整備
• テスト基盤環境の開発
• iOS Test Nightの主催
Copyright © DeNA Co.,Ltd. All Rights Reserved.
今日の発表の流れ
 はじめに
 UIテストの実行時間の短縮のための方法
⁃ [1] テスト実行の並列化
• テストの実行時間の比較
⁃ [2] テスト実行計画の最適化
 まとめ
Copyright © DeNA Co.,Ltd. All Rights Reserved.
はじめに
 iOSアプリのUIテストの課題(の1つ)
⁃ → テストの実行時間
 解決方法の手段(の1つ)
⁃ [1] ビルドとテストの実行を分割して並列化
• 1) テストのためにビルド
⁃ build-for-testingコマンドで実行
• 2) テストを実行
⁃ test-without-buildingコマンドで実行
⁃ bluepillを利用
⁃ pxctestを利用
⁃ [2] テストの実行時間を元にした並列実行計画
Copyright © DeNA Co.,Ltd. All Rights Reserved.
[1] 実際に実行時間を比較してみる
 実行時間を比較する対象一覧
⁃ (1) fastlane scan (xcodebuild test)
• 素のまま
⁃ (2) build-for-testing / test-without-building
• ビルドと実行をわける
⁃ (3) bluepill
• ツールを利用(1)
⁃ (4) pxctest
• ツールを利用(2)
Copyright © DeNA Co.,Ltd. All Rights Reserved.
それぞれの(簡単な)説明
 基本機能
⁃ (1) fastlane scan (xcodebuild test)
⁃ (2) build-for-testing / test-without-building
• ビルドとテストの実行を分割
 複数iOSシミュレーターを起動させることが出来るツール
※注意※ build-for-testingでビルドしたものがある前提
⁃ (3) bluepill / inspired by FBSimulatorControl
• https://github.com/linkedin/bluepill
• 指定したシミュレーター数に応じてテストケースを分割して実行
⁃ (4) pxctest / using FBSimulatorControl
• https://github.com/plu/pxctest
• 複数のシミュレーターで同じテストケースを全て実行
Copyright © DeNA Co.,Ltd. All Rights Reserved.
今回の実行条件
 UIテストについて
⁃ 利用したフレームワーク:XCTest / UI Testing
⁃ クラス数:6
⁃ テストケース数:15
• 5 + 1 + 2 + 2 + 2 + 3 = 15
 実行環境(Jenkins)
⁃ Mac Pro (Late 2013)
• 3.5GHz 6コア / 16GB
• OS: 10.12.4
• Xcode 8.3.2
Copyright © DeNA Co.,Ltd. All Rights Reserved.
(1) fastlane scan (xcodebuild test) の結果 / ベースとなる数値
試行数:10
 平均:392.3
 最大:405
 最小:388
 中央値:390
当然ながら一番実行時間がかかっています。
Fastfileでの記述例
scan(
sdk: “iphonesimulator”,
configuration: "Release",
output_directory: “test-report/”,
buildlog_path: “test-report/”,
output_types: “html,junit”,
)
Copyright © DeNA Co.,Ltd. All Rights Reserved.
(2) build-for-testing / test-without-buildingの結果
試行数:10 / ビルド時間:54
 平均:284.9
 最大:287
 最小:284
 中央値:285
テストを実行するマシンの数を増やせばもっと早くなる。
Fastfileでの記述例 / test-without-building
scan(
xctestrun: “path/to/xxx.xctestrun” #このkeyがあるとtest-without-buildingと判断される
device: “iPhone 7”
output_directory: 'test-report/',
buildlog_path: 'test-report/',
output_types: 'html,junit',
)
Copyright © DeNA Co.,Ltd. All Rights Reserved.
build-for-testing / test-without-buildingの利用例
 ビルドマシン
⁃ build-for-testing
 テスト実行マシン #1
⁃ test-without-building
• テストクラスAを指定
 テスト実行マシン#2
⁃ test-without-building
• テストクラスBを指定
このテスト実行マシンを増やすことにより並列化が進み実行時間が短縮する。
ビルド成果物
テスト実行#1 テスト実行#2
Copyright © DeNA Co.,Ltd. All Rights Reserved.
(3) bluepill(v 1.1.0)の結果
試行数:10 / シミュレーター数:3 / ビルド時間:54
 平均:165.9
 最大:183
 最小:162
 中央値:164.5
Fastfileでの記述例 / pluginがあります(2つ)
※独自actionを作成しました
bluepill(
app: “path/to/xxxx.app”
scheme: “path/to/xxxx.xcscheme”
output_dir: 'test-report/',
device: “iPhone 7”,
number_of_simulators: 3,
)
bluepillのplugin
1) https://github.com/tbrand/fastlane-plugin-bluepill
2) https://github.com/Shashikant86/fastlane-plugin-bluepillar
シミュレーター数が4の場合:[平均:165.5]
シミュレーター数が5の場合:[平均:134.4]
Copyright © DeNA Co.,Ltd. All Rights Reserved.
(4) pxctest(v 0.3.2)の結果
試行数:10 / シミュレーター数:1 / ビルド時間:54
 平均:222.3
 最大:224
 最小:219
 中央値:222.5
Fastfileでの記述例
※独自actionを作成しました
pxctest(
testrun: “path/to/xxxx.xctestrun”,
output: “test-report”,
destinations: destinations
)
シミュレーター数が3(テスト数:45)の場合:[平均:285.4]
Copyright © DeNA Co.,Ltd. All Rights Reserved.
テストの実行時間の比較
対象 テストケース数 平均(sec)
fastlane scan ( xcodebuild test ) 15 392.3
build-for-testing
test-without-building
(テスト実行マシン:1)
15 284.9
bluepill (シミュレーター数:3) 15 165.9
bluepill (シミュレーター数:5) 15 134.4
pxctest (シミュレーター数:1) 15 222.3
pxctest (シミュレーター数:3) 45 285.4
Copyright © DeNA Co.,Ltd. All Rights Reserved.
[2] テストの実行時間を元にした並列実行計画
テストの実行時間にはばらつきがあるので最適化する
実行マシンが3つある場合
(1) 113
(2) 10 + 19 + 19 + 31 = 79
(3) 57
実行マシンが2つある場合
(1): 113 + 10 = 123
(2): 19 + 19 + 31 + 57 = 126
113
手動での設定も出来るけどテストは追加・削除されるので自動化したい
Copyright © DeNA Co.,Ltd. All Rights Reserved.
ポメラニアン(SWET製):自動テストをサポートするサービス
 機能(の一部)
⁃ 不安定なテストの検出
⁃ 並列実行の計画の最適化
 利用フロー
1. テストの実行結果を送る
• 実行時間などの結果が履歴に保存されていく
2. テスト計画を依頼する
• 何台のマシンで実行するか
3. 今までの履歴を元に計画を教えてくれる
4. 得た情報を元にテストを実行する
• test-without-buildingとテスト実行マシンがあれば出来る
⁃ ※あとはポメラニアンクライアント
Copyright © DeNA Co.,Ltd. All Rights Reserved.
おわりに
 UIテストの実行時間を短縮させる方法
⁃ 並列化をおこなってしまおう
• 1つのシミュレーターのみでOKなら → bluepill
• カバレッジとりたいなら → pxctest
⁃ テストの実行時間のばらつきを最適化する
• クラス単位における実行時間に基づきグルーピング
他にも方法はあるはずなので試した内容の発表をお待ちしています!

UIテストの実行時間の短縮の方法

  • 1.
    Copyright © DeNACo.,Ltd. All Rights Reserved. iOS Test Night #4 2017/05/22(Mon) 平田敏之@DeNA UIテストの実行時間の短縮の方法 - test-without-building / bluepill / pxctest / Pomeranian -
  • 2.
    Copyright © DeNACo.,Ltd. All Rights Reserved. 自己紹介  平田 敏之@DeNA ⁃ SWET (Software Engineer in Test) • 事業サポートチーム / テスト基盤チーム • ミッション ⁃ DeNAサービス全般の品質向上 ⁃ DeNAエンジニアの開発生産性向上 ⁃ 私がやっていること(の一部) • クライアントアプリ周りのテスト戦略、自動テストの開発 • CI/CD環境整備 • テスト基盤環境の開発 • iOS Test Nightの主催
  • 3.
    Copyright © DeNACo.,Ltd. All Rights Reserved. 今日の発表の流れ  はじめに  UIテストの実行時間の短縮のための方法 ⁃ [1] テスト実行の並列化 • テストの実行時間の比較 ⁃ [2] テスト実行計画の最適化  まとめ
  • 4.
    Copyright © DeNACo.,Ltd. All Rights Reserved. はじめに  iOSアプリのUIテストの課題(の1つ) ⁃ → テストの実行時間  解決方法の手段(の1つ) ⁃ [1] ビルドとテストの実行を分割して並列化 • 1) テストのためにビルド ⁃ build-for-testingコマンドで実行 • 2) テストを実行 ⁃ test-without-buildingコマンドで実行 ⁃ bluepillを利用 ⁃ pxctestを利用 ⁃ [2] テストの実行時間を元にした並列実行計画
  • 5.
    Copyright © DeNACo.,Ltd. All Rights Reserved. [1] 実際に実行時間を比較してみる  実行時間を比較する対象一覧 ⁃ (1) fastlane scan (xcodebuild test) • 素のまま ⁃ (2) build-for-testing / test-without-building • ビルドと実行をわける ⁃ (3) bluepill • ツールを利用(1) ⁃ (4) pxctest • ツールを利用(2)
  • 6.
    Copyright © DeNACo.,Ltd. All Rights Reserved. それぞれの(簡単な)説明  基本機能 ⁃ (1) fastlane scan (xcodebuild test) ⁃ (2) build-for-testing / test-without-building • ビルドとテストの実行を分割  複数iOSシミュレーターを起動させることが出来るツール ※注意※ build-for-testingでビルドしたものがある前提 ⁃ (3) bluepill / inspired by FBSimulatorControl • https://github.com/linkedin/bluepill • 指定したシミュレーター数に応じてテストケースを分割して実行 ⁃ (4) pxctest / using FBSimulatorControl • https://github.com/plu/pxctest • 複数のシミュレーターで同じテストケースを全て実行
  • 7.
    Copyright © DeNACo.,Ltd. All Rights Reserved. 今回の実行条件  UIテストについて ⁃ 利用したフレームワーク:XCTest / UI Testing ⁃ クラス数:6 ⁃ テストケース数:15 • 5 + 1 + 2 + 2 + 2 + 3 = 15  実行環境(Jenkins) ⁃ Mac Pro (Late 2013) • 3.5GHz 6コア / 16GB • OS: 10.12.4 • Xcode 8.3.2
  • 8.
    Copyright © DeNACo.,Ltd. All Rights Reserved. (1) fastlane scan (xcodebuild test) の結果 / ベースとなる数値 試行数:10  平均:392.3  最大:405  最小:388  中央値:390 当然ながら一番実行時間がかかっています。 Fastfileでの記述例 scan( sdk: “iphonesimulator”, configuration: "Release", output_directory: “test-report/”, buildlog_path: “test-report/”, output_types: “html,junit”, )
  • 9.
    Copyright © DeNACo.,Ltd. All Rights Reserved. (2) build-for-testing / test-without-buildingの結果 試行数:10 / ビルド時間:54  平均:284.9  最大:287  最小:284  中央値:285 テストを実行するマシンの数を増やせばもっと早くなる。 Fastfileでの記述例 / test-without-building scan( xctestrun: “path/to/xxx.xctestrun” #このkeyがあるとtest-without-buildingと判断される device: “iPhone 7” output_directory: 'test-report/', buildlog_path: 'test-report/', output_types: 'html,junit', )
  • 10.
    Copyright © DeNACo.,Ltd. All Rights Reserved. build-for-testing / test-without-buildingの利用例  ビルドマシン ⁃ build-for-testing  テスト実行マシン #1 ⁃ test-without-building • テストクラスAを指定  テスト実行マシン#2 ⁃ test-without-building • テストクラスBを指定 このテスト実行マシンを増やすことにより並列化が進み実行時間が短縮する。 ビルド成果物 テスト実行#1 テスト実行#2
  • 11.
    Copyright © DeNACo.,Ltd. All Rights Reserved. (3) bluepill(v 1.1.0)の結果 試行数:10 / シミュレーター数:3 / ビルド時間:54  平均:165.9  最大:183  最小:162  中央値:164.5 Fastfileでの記述例 / pluginがあります(2つ) ※独自actionを作成しました bluepill( app: “path/to/xxxx.app” scheme: “path/to/xxxx.xcscheme” output_dir: 'test-report/', device: “iPhone 7”, number_of_simulators: 3, ) bluepillのplugin 1) https://github.com/tbrand/fastlane-plugin-bluepill 2) https://github.com/Shashikant86/fastlane-plugin-bluepillar シミュレーター数が4の場合:[平均:165.5] シミュレーター数が5の場合:[平均:134.4]
  • 12.
    Copyright © DeNACo.,Ltd. All Rights Reserved. (4) pxctest(v 0.3.2)の結果 試行数:10 / シミュレーター数:1 / ビルド時間:54  平均:222.3  最大:224  最小:219  中央値:222.5 Fastfileでの記述例 ※独自actionを作成しました pxctest( testrun: “path/to/xxxx.xctestrun”, output: “test-report”, destinations: destinations ) シミュレーター数が3(テスト数:45)の場合:[平均:285.4]
  • 13.
    Copyright © DeNACo.,Ltd. All Rights Reserved. テストの実行時間の比較 対象 テストケース数 平均(sec) fastlane scan ( xcodebuild test ) 15 392.3 build-for-testing test-without-building (テスト実行マシン:1) 15 284.9 bluepill (シミュレーター数:3) 15 165.9 bluepill (シミュレーター数:5) 15 134.4 pxctest (シミュレーター数:1) 15 222.3 pxctest (シミュレーター数:3) 45 285.4
  • 14.
    Copyright © DeNACo.,Ltd. All Rights Reserved. [2] テストの実行時間を元にした並列実行計画 テストの実行時間にはばらつきがあるので最適化する 実行マシンが3つある場合 (1) 113 (2) 10 + 19 + 19 + 31 = 79 (3) 57 実行マシンが2つある場合 (1): 113 + 10 = 123 (2): 19 + 19 + 31 + 57 = 126 113 手動での設定も出来るけどテストは追加・削除されるので自動化したい
  • 15.
    Copyright © DeNACo.,Ltd. All Rights Reserved. ポメラニアン(SWET製):自動テストをサポートするサービス  機能(の一部) ⁃ 不安定なテストの検出 ⁃ 並列実行の計画の最適化  利用フロー 1. テストの実行結果を送る • 実行時間などの結果が履歴に保存されていく 2. テスト計画を依頼する • 何台のマシンで実行するか 3. 今までの履歴を元に計画を教えてくれる 4. 得た情報を元にテストを実行する • test-without-buildingとテスト実行マシンがあれば出来る ⁃ ※あとはポメラニアンクライアント
  • 16.
    Copyright © DeNACo.,Ltd. All Rights Reserved. おわりに  UIテストの実行時間を短縮させる方法 ⁃ 並列化をおこなってしまおう • 1つのシミュレーターのみでOKなら → bluepill • カバレッジとりたいなら → pxctest ⁃ テストの実行時間のばらつきを最適化する • クラス単位における実行時間に基づきグルーピング 他にも方法はあるはずなので試した内容の発表をお待ちしています!