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
560
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
170
Androidアプリの良いユニットテストを考える / Thinking about good unit tests for Android apps
tkmnzm
5
7k
コルーチンのエラーをテストするためのTips / Tips for testing Kotlin Coroutine errors
tkmnzm
0
840
Androidのモダンな技術選択にあわせて自動テストも アップデートしよう / Update your automated tests to match Android's modern technology choices
tkmnzm
2
2k
SWET dev-vitalチームによるプロジェクトの健康状態可視化の取り組み / SWET dev-vital team's efforts to visualize the health of the project
tkmnzm
1
1.2k
モバイルアプリテスト入門 / Getting Started with Mobile App Testing
tkmnzm
1
440
25分で作るAndroid Lint / Android Lint made in 25 minutes
tkmnzm
0
830
2年半ぶりのプロダクト開発であらためて感じた自動テストの大切さ / realized the importance of automatic testing with product development for the first time in two and a half years
tkmnzm
1
730
Android スクリーンショットテスト 3つのプロダクトに導入する中で倒してきた課題 / Android Screenshot Test Problems solved by introducing into 3 products
tkmnzm
2
1.2k
Other Decks in Technology
See All in Technology
技術的負債解消の取り組みと専門チームのお話
bengo4com
0
330
再考 アクターモデル/ reconsider actor model
ytake
0
360
事前準備が肝!AI活用のための業務改革
layerx
PRO
1
380
突撃! 隣のAmazon Bedrockユーザー 〜YouはどうしてAWSで?〜
minorun365
PRO
3
390
Jetpack Compose Modifier 徹底解説 / Jetpack Compose Modifier
wiroha
0
200
タイミーのレコメンドにおける ABテストの運用
ozeshun
1
140
Google CloudのLLM活用の選択肢を広げるVertex AIのパートナーモデル
nayuts
0
130
OR学会2024秋_短期収益と将来のオフ方策評価性能を考慮したクーポン割当方策混合比の決定
recruitengineers
PRO
4
460
不動産 x AIことはじめ~データの真価を拓くために
estie
0
110
DevRelの始め方
moongift
PRO
1
390
OSTという文化を組織に根付かせてみた
sansantech
PRO
2
380
Creative UIs with Compose: DroidKaigi 2024
chrishorner
1
580
Featured
See All Featured
Creatively Recalculating Your Daily Design Routine
revolveconf
215
12k
GraphQLの誤解/rethinking-graphql
sonatard
65
9.8k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.4k
Mobile First: as difficult as doing things right
swwweet
221
8.8k
Why Our Code Smells
bkeepers
PRO
334
56k
Building Better People: How to give real-time feedback that sticks.
wjessup
359
19k
What the flash - Photography Introduction
edds
67
11k
Debugging Ruby Performance
tmm1
72
12k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
103
48k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
24
610
A Modern Web Designer's Workflow
chriscoyier
691
190k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
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/