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
500
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
5.7k
コルーチンのエラーをテストするためのTips / Tips for testing Kotlin Coroutine errors
tkmnzm
0
600
Androidのモダンな技術選択にあわせて自動テストも アップデートしよう / Update your automated tests to match Android's modern technology choices
tkmnzm
2
1.8k
SWET dev-vitalチームによるプロジェクトの健康状態可視化の取り組み / SWET dev-vital team's efforts to visualize the health of the project
tkmnzm
1
1.1k
モバイルアプリテスト入門 / Getting Started with Mobile App Testing
tkmnzm
1
350
25分で作るAndroid Lint / Android Lint made in 25 minutes
tkmnzm
0
790
2年半ぶりのプロダクト開発であらためて感じた自動テストの大切さ / realized the importance of automatic testing with product development for the first time in two and a half years
tkmnzm
1
670
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
Terraformあれやこれ/terraform-this-and-that
emiki
7
600
Vertex AI を中心に 生成AIのアップデートを共有します
kaz1437
0
150
現代CSSフレームワークの内部実装とその仕組み
poteboy
6
1.8k
AWS を使う上で知っておきたいオンプレミス知識/aws-on-premise-essentials
emiki
1
4.2k
KubeCon EU 2024 Recap “Kubernetes Policy Time Machine: Where to Next?”
ryysud
0
140
DevOpsメトリクスとアウトカムの接続にトライ!開発プロセスを通して計測できるメトリクスの活用方法
ham0215
2
200
SREとその組織類型
tatsuo48
8
1.5k
AIQ株式会社 エンジニア向け会社紹介資料
aiqlab
0
380
0→1開発における技術選定において一番大切なこと
bicstone
1
330
疲弊しない!AWSセキュリティ統制の考え方 #devio_osakaday1
masahirokawahara
6
5.9k
オブザーバビリティの Primary Signals
onk
PRO
0
550
Microsoft Cloudで開発ライフサイクルを保護する
kkamegawa
0
150
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
124
32k
The Language of Interfaces
destraynor
151
23k
Thoughts on Productivity
jonyablonski
57
3.8k
Why Our Code Smells
bkeepers
PRO
331
56k
Documentation Writing (for coders)
carmenintech
59
3.9k
What's new in Ruby 2.0
geeforr
337
31k
Raft: Consensus for Rubyists
vanstee
132
6.2k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
The Brand Is Dead. Long Live the Brand.
mthomps
48
28k
How STYLIGHT went responsive
nonsquared
92
4.8k
A Modern Web Designer's Workflow
chriscoyier
688
190k
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/