Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Google I:O 2023 Androidの自動テストアップデートまとめ / Goog...
Search
tkmnzm
May 26, 2023
Technology
0
600
Google I:O 2023 Androidの自動テストアップデートまとめ / Google I:O 2023 Android Testing Update Recap
Shibuya.apk #42の発表資料です。
https://shibuya-apk.connpass.com/event/283427/
tkmnzm
May 26, 2023
Tweet
Share
More Decks by tkmnzm
See All by tkmnzm
AndroidアプリのUIバリエーションをあの手この手で確認する / Check UI variations of Android apps by various means
tkmnzm
1
1.1k
Androidアプリの良いユニットテストを考える / Thinking about good unit tests for Android apps
tkmnzm
5
8.1k
コルーチンのエラーをテストするためのTips / Tips for testing Kotlin Coroutine errors
tkmnzm
0
1k
Androidのモダンな技術選択にあわせて自動テストも アップデートしよう / Update your automated tests to match Android's modern technology choices
tkmnzm
3
2.2k
SWET dev-vitalチームによるプロジェクトの健康状態可視化の取り組み / SWET dev-vital team's efforts to visualize the health of the project
tkmnzm
1
1.3k
モバイルアプリテスト入門 / Getting Started with Mobile App Testing
tkmnzm
1
530
25分で作るAndroid Lint / Android Lint made in 25 minutes
tkmnzm
0
880
2年半ぶりのプロダクト開発であらためて感じた自動テストの大切さ / realized the importance of automatic testing with product development for the first time in two and a half years
tkmnzm
1
780
Android スクリーンショットテスト 3つのプロダクトに導入する中で倒してきた課題 / Android Screenshot Test Problems solved by introducing into 3 products
tkmnzm
2
1.2k
Other Decks in Technology
See All in Technology
エンジニアリング価値を黒字化する バリューベース戦略を用いた 技術戦略策定の道のり
kzkmaeda
7
3k
EDRの検知の仕組みと検知回避について
chayakonanaika
12
5.1k
スキルだけでは満たせない、 “組織全体に”なじむオンボーディング/Onboarding that fits “throughout the organization” and cannot be satisfied by skills alone
bitkey
0
190
AIエージェント元年@日本生成AIユーザ会
shukob
1
230
Apache Iceberg Case Study in LY Corporation
lycorptech_jp
PRO
0
340
困難を「一般解」で解く
fujiwara3
7
1.2k
生成AI “再”入門 2025年春@WIRED TUESDAY EDITOR'S LOUNGE
kajikent
0
140
30→150人のエンジニア組織拡大に伴うアジャイル文化を醸成する役割と取り組みの変化
nagata03
0
190
Snowflake ML モデルを dbt データパイプラインに組み込む
estie
0
110
急成長する企業で作った、エンジニアが輝ける制度/ 20250227 Rinto Ikenoue
shift_evolve
0
160
JavaにおけるNull非許容性
skrb
2
2.7k
Change Managerを活用して本番環境へのセキュアなGUIアクセスを統制する / Control Secure GUI Access to the Production Environment with Change Manager
yuj1osm
0
100
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
91
5.9k
YesSQL, Process and Tooling at Scale
rocio
172
14k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Being A Developer After 40
akosma
89
590k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
52k
Thoughts on Productivity
jonyablonski
69
4.5k
It's Worth the Effort
3n
184
28k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
430
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
Transcript
Google I/O 2023 Android の自動テスト アップデートまとめ Shibuya.apk #42 Nozomi Takuma
自己紹介 Nozomi Takuma 株式会社ディー・エヌ・エー SWET グループ Android とテストが好き
Google I/O 2023 Android のテスト関連セッシ ョン Scalable UI testing solutions
How to test across all screen sizes
Scalable UI testing solutions Espresso Device API Gradle Managed Device
のFirebase Test Lab サポート スクリーンショットテスト
How to test across all screen sizes 様々な画面サイズに対応するためにテストするべきこと 手動でのテストで使えるツール Large
screen emulators & Resizable emulators デバイスミラーリング Multi Previews for Compose 自動テスト 様々な画面サイズのテストで使えるAPI window-testing, StateRestorationTester, Test Harness
Scalable UI testing solutions Espresso Device API Gradle Managerd Device
のFirebase Test Lab サポート スクリーンショットテスト
Espresso Device API https://developer.android.com/studio/preview/features/#espresso- device-api デバイスの回転や折りたたみデバイスの開閉などのConfiguration change が発生した時のテストができる 同期的に実行されるので、Configuration change
を待ち合わせるた めのsleep が不要 androidx.test.espresso:espresso-device
Espresso Device API を使用するのに必要な環 境 Android Studio Hedgehog Canary 2+
Android Gradle 8.2+ Android エミュレータ 33.1.10+ API レベル 24 以上のエミュレーター 実機はPixel Fold 、Pixel Tablet のみ対応 持っていないけど実機使いたい場合はFirebase Test Lab を使う
画面回転のテスト // テスト起動時の初期状態を縦向きに設定する @get:Rule val screenOrientationRule = ScreenOrientationRule(ScreenOrientation.PORTRAIT) @Test fun
testRotation() { // 横向きにする onDevice().setScreenOrientation(ScreenOrientation.LANDSCAPE) // Espresso やComposeTestRule を使って状態をアサートする // 同期してくれるのでsleep がいらない composeTestRule.onNodeWithTag("Agree Button").assertIsDisplayed() }
Foldable 端末のテスト @Test fun testFoldable() { // 折り畳んだ状態にする onDevice().setClosedMode() //
完全に開かれた状態にする onDevice().setFlatMode() }
テストを実行するデバイスの指定 Foldable 端末用のテストを、Folable 端末ではないデバイスで実行しな いようにする @Test @RequiresDeviceMode(mode = FLAT) fun
test() { ... }
Scalable UI testing solutions Espresso Device API Gradle Managed Device
の Firebase Test Lab サポート スクリーンショットテスト
Gradle Managed Device https://developer.android.com/studio/test/gradle-managed-devices build.gradle にテストを実行するエミュレータの構成を定義すると、 AVD 作成からテスト実行までGradle が自動でやってくれる managedDevices
{ devices { pixel2api30 (com.android.build.api.dsl.ManagedVirtualDevice) { device = "Pixel 2" apiLevel = 30 systemImageSource = "aosp" } } }
Gradle Managed Device の Firebase Test Lab サ ポート https://developer.android.com/studio/preview/features/#ftl-gmd
GMD でFirebase Test Lab のデバイスが扱えるように firebaseTestLab { managedDevices { create("ftlDevice") { device = "Pixel3" apiLevel = 30 } } }
Scalable UI testing solutions Espresso Device API Gradle Managed Device
のFirebase Test Lab サポート スクリーンショットテスト
スクリーンショットテスト AGP8.2 に、Local Test テストでCompose のプレビューのスクリーン ショットテストを実行できる機能を追加予定 リファレンスの画像の保存と、リファレンス画像と現在の画像を比 較するVisual Regression
テストを実行するタスクが追加される Experimental なのでpreview のリリースノートを見てね
スクリーンショットテスト使い方 ( 予定 ) src/screenshotTest のソースセットを追加し、テストしたい Compose のPreview のコードを置く ./gradlew
debugScreenshotTest –record-reference-images でリファ レンス画像の作成 ./gradlew debugScreenshotTest でVisual Regression テストの実行
Scalable UI testing solutions Espresso Device API Gradle Managed Device
のFirebase Test Lab サポート スクリーンショットテスト
How to test across all screen sizes 様々な画面サイズに対応するためにテストするべきこと 手動でのテストで使えるツール Large
screen emulators & Resizable emulators デバイスミラーリング Multi Previews for Compose 自動テスト 様々な画面サイズのテストで使えるAPI window-testing, StateRestorationTester, Test Harness
How to test across all screen sizes 様々な画面サイズに対応するためにテストするべきこと 手動でのテストで使えるツール Large
screen emulators & Resizable emulators デバイスミラーリング Multi Previews for Compose 自動テスト 様々な画面サイズのテストで使えるAPI window-testing, StateRestorationTester, Test Harness
window-testing Jetpack Window Manager のテストライブラリ WindowLayoutInfoPublisherRule でFoldable 端末の折りたたみ状態 をエミュレート 使い方を学べるCodelab
https://developer.android.com/codelabs/android-window- manager-dual-screen-foldables
WindowLayoutInfoPublisherRule セットアップ androidTestImplementation "androidx.window:window-testing:$windowmanager_version" @get:Rule(order = 0) val publisherRule =
WindowLayoutInfoPublisherRule() @get:Rule(order = 1) val activityRule = ActivityScenarioRule(MainActivity::class.java)
WindowLayoutInfoPublisherRule @Test fun testFoldingFeature() { activityRule.scenario.onActivity { activity -> //
折りたたみの状態を任意の設定にして上書きする val hinge = FoldingFeature( activity = activity, state = FLAT, orientation = VERTICAL, size = 2 ) val expected = TestWindowLayoutInfo(listOf(hinge)) publisherRule.overrideWindowLayoutInfo(expected) } }
val hinge = FoldingFeature( activity = activity, state = FLAT,
orientation = VERTICAL, size = 2 )
val hinge = FoldingFeature( activity = activity, state = FLAT,
orientation = HORIZONTAL, size = 2 )
StateRestorationTester Compose のConfiguration Change 時の振る舞いをテストできる 使い方を学べるCodelab https://developer.android.com/codelabs/basic-android-kotlin- compose-adaptive-content-for-large-screens セットアップ implementation
platform('androidx.compose:compose-bom:2023.01.00') androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
StateRestorationTester @get:Rule val composeTestRule = createAndroidComposeRule<ComponentActivity>() @Test fun stateRestoreTest() {
val stateRestorationTester = StateRestorationTester(composeTestRule) stateRestorationTester.setContent { MyConmponent() } // 再生成された状態をエミュレート stateRestorationTester.emulateSavedInstanceStateRestore() // assert }
Test Harness Compose 用のテストライブラリ(accompanist) ロケール、フォント サイズ、画面サイズに任意のものを指定して Compose のテストをすることができる セットアップ implementation
"com.google.accompanist:accompanist-testharness:<version>"
Test Harness @Test fun test() { composeTestRule.setContent { // TestHarness
でテストしたいComposable Function を囲む TestHarness( size = DpSize(800.dp, 1000.dp), fontScale = 1.5f, locales = LocaleListCompat.getDefault(), layoutDirection = LayoutDirection.Ltr, ) { MyConmponent() } } }
まとめ Google I/O 2023 Android のテスト関連セッション Scalable UI testing solutions
How to test across all screen sizes Pixel Fold やPixel Tablet の登場に合わせて、様々なデバイスに対応 させるためのUI テストの手段が紹介されていた Local Test でのスクリーンショットテストと組み合わせたり、UI テ ストの幅が広がる期待感がありました
宣伝 一緒に働いてくれるメンバーを募集中です! https://engineering.dena.com/team/quality/swet/