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の自動テストアップデートまとめ / Google I:O 2023 Android Testing Update Recap
Search
tkmnzm
May 26, 2023
Technology
0
540
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アプリの良いユニットテストを考える / Thinking about good unit tests for Android apps
tkmnzm
5
6.5k
コルーチンのエラーをテストするためのTips / Tips for testing Kotlin Coroutine errors
tkmnzm
0
740
Androidのモダンな技術選択にあわせて自動テストも アップデートしよう / Update your automated tests to match Android's modern technology choices
tkmnzm
2
1.9k
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
410
25分で作るAndroid Lint / Android Lint made in 25 minutes
tkmnzm
0
820
2年半ぶりのプロダクト開発であらためて感じた自動テストの大切さ / realized the importance of automatic testing with product development for the first time in two and a half years
tkmnzm
1
710
Android スクリーンショットテスト 3つのプロダクトに導入する中で倒してきた課題 / Android Screenshot Test Problems solved by introducing into 3 products
tkmnzm
2
1.1k
Jetpack Composeの テストに入門しよう / Getting started with Jetpack Compose Testing
tkmnzm
1
1.1k
Other Decks in Technology
See All in Technology
AI研修【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
130
推薦システムを本番導入する上で一番優先すべきだったこと~NewsPicks記事推薦機能の改善事例を元に~
morinota
0
120
Azure Pipelinesを使用したCICDベースラインアーキテクチャ実践
yuriemori
0
190
How to Think Like a Performance Engineer
csswizardry
4
590
ゆめみのアクセシビリティの現在地と今後
ryokatsuse
3
290
大規模ドラレコデータ収集・機械学習基盤を支える AWS CDK 〜導入・運用事例紹介〜
pemugi
0
110
Classmethod Odyssey 登壇資料
yamahiro
0
390
「単なる OAuth 2.0 を認証に使うと、車が通れるほどのどでかいセキュリティー・ホールができる」のか検証してみた
terara
0
380
さらに高品質・高速化を目指すAI時代のテスト設計支援と、めざす先 / AI Test Lab vol.1
shift_evolve
0
190
データ分析を支える技術 生成AI再入門
ishikawa_satoru
0
380
LINE WORKSへ簡単通知!Incoming Webhookアプリの紹介
mmclsntr
0
110
RAGのサービスをリリースして1年3ヶ月が経ちました
segavvy
4
900
Featured
See All Featured
Robots, Beer and Maslow
schacon
PRO
157
8.1k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
Automating Front-end Workflow
addyosmani
1362
200k
Designing for Performance
lara
604
67k
Creatively Recalculating Your Daily Design Routine
revolveconf
214
11k
The Invisible Side of Design
smashingmag
294
50k
Thoughts on Productivity
jonyablonski
64
4.1k
What's in a price? How to price your products and services
michaelherold
239
11k
A Philosophy of Restraint
colly
200
16k
Writing Fast Ruby
sferik
623
60k
WebSockets: Embracing the real-time Web
robhawkes
59
7.2k
From Idea to $5000 a Month in 5 Months
shpigford
377
46k
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/