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
620
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.2k
Androidアプリの良いユニットテストを考える / Thinking about good unit tests for Android apps
tkmnzm
5
8.4k
コルーチンのエラーをテストするためのTips / Tips for testing Kotlin Coroutine errors
tkmnzm
0
1.1k
Androidのモダンな技術選択にあわせて自動テストも アップデートしよう / Update your automated tests to match Android's modern technology choices
tkmnzm
3
2.3k
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
550
25分で作るAndroid Lint / Android Lint made in 25 minutes
tkmnzm
0
910
2年半ぶりのプロダクト開発であらためて感じた自動テストの大切さ / realized the importance of automatic testing with product development for the first time in two and a half years
tkmnzm
1
800
Android スクリーンショットテスト 3つのプロダクトに導入する中で倒してきた課題 / Android Screenshot Test Problems solved by introducing into 3 products
tkmnzm
2
1.2k
Other Decks in Technology
See All in Technology
使えるデータ基盤を作る技術選定の秘訣 / selecting-the-right-data-technology
pei0804
5
930
AIと共同執筆してより質の高い記事を書こう
riyaamemiya
1
310
正式リリースされた Semantic Kernel の Agent Framework 全部紹介!
okazuki
1
1.1k
LangfuseではじめるAIアプリのLLMトレーシング
codenote
0
140
AI-in-the-Enterprise|OpenAIが公開した「AI導入7つの教訓」——ChatGPTで変わる企業の未来とは?
customercloud
PRO
0
160
OPENLOGI Company Profile
hr01
0
64k
Cursorを全エンジニアに配布 その先に見据えるAI駆動開発の未来 / 2025-05-13-forkwell-ai-study-1-cursor-at-loglass
itohiro73
2
450
Azure & DevSecOps
kkamegawa
2
180
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
5.5k
AI駆動で進化する開発プロセス ~クラスメソッドでの実践と成功事例~ / aidd-in-classmethod
tomoki10
1
1k
続・やっぱり余白が大切だった話
kakehashi
PRO
3
310
Aspire をカスタマイズしよう & Aspire 9.2
nenonaninu
0
380
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Automating Front-end Workflow
addyosmani
1370
200k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
Product Roadmaps are Hard
iamctodd
PRO
53
11k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
Why Our Code Smells
bkeepers
PRO
336
57k
Music & Morning Musume
bryan
47
6.5k
Designing for Performance
lara
608
69k
How to Think Like a Performance Engineer
csswizardry
23
1.6k
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/