Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Google I:O 2023 Androidの自動テストアップデートまとめ / Google I:O 2023 Android Testing Update Recap

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

More Decks by tkmnzm

Other Decks in Technology

Transcript

  1. Scalable UI testing solutions Espresso Device API Gradle Managed Device

    のFirebase Test Lab サポート スクリーンショットテスト
  2. How to test across all screen sizes 様々な画面サイズに対応するためにテストするべきこと 手動でのテストで使えるツール Large

    screen emulators & Resizable emulators デバイスミラーリング Multi Previews for Compose 自動テスト 様々な画面サイズのテストで使えるAPI window-testing, StateRestorationTester, Test Harness
  3. Scalable UI testing solutions Espresso Device API Gradle Managerd Device

    のFirebase Test Lab サポート スクリーンショットテスト
  4. 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 を使う
  5. 画面回転のテスト // テスト起動時の初期状態を縦向きに設定する @get:Rule val screenOrientationRule = ScreenOrientationRule(ScreenOrientation.PORTRAIT) @Test fun

    testRotation() { // 横向きにする onDevice().setScreenOrientation(ScreenOrientation.LANDSCAPE) // Espresso やComposeTestRule を使って状態をアサートする // 同期してくれるのでsleep がいらない composeTestRule.onNodeWithTag("Agree Button").assertIsDisplayed() }
  6. Scalable UI testing solutions Espresso Device API Gradle Managed Device

    の Firebase Test Lab サポート スクリーンショットテスト
  7. 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 } } }
  8. Scalable UI testing solutions Espresso Device API Gradle Managed Device

    のFirebase Test Lab サポート スクリーンショットテスト
  9. スクリーンショットテスト使い方 ( 予定 ) src/screenshotTest のソースセットを追加し、テストしたい Compose のPreview のコードを置く ./gradlew

    debugScreenshotTest –record-reference-images でリファ レンス画像の作成 ./gradlew debugScreenshotTest でVisual Regression テストの実行
  10. Scalable UI testing solutions Espresso Device API Gradle Managed Device

    のFirebase Test Lab サポート スクリーンショットテスト
  11. How to test across all screen sizes 様々な画面サイズに対応するためにテストするべきこと 手動でのテストで使えるツール Large

    screen emulators & Resizable emulators デバイスミラーリング Multi Previews for Compose 自動テスト 様々な画面サイズのテストで使えるAPI window-testing, StateRestorationTester, Test Harness
  12. How to test across all screen sizes 様々な画面サイズに対応するためにテストするべきこと 手動でのテストで使えるツール Large

    screen emulators & Resizable emulators デバイスミラーリング Multi Previews for Compose 自動テスト 様々な画面サイズのテストで使えるAPI window-testing, StateRestorationTester, Test Harness
  13. 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)
  14. 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) } }
  15. StateRestorationTester @get:Rule val composeTestRule = createAndroidComposeRule<ComponentActivity>() @Test fun stateRestoreTest() {

    val stateRestorationTester = StateRestorationTester(composeTestRule) stateRestorationTester.setContent { MyConmponent() } // 再生成された状態をエミュレート stateRestorationTester.emulateSavedInstanceStateRestore() // assert }
  16. 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() } } }
  17. まとめ Google I/O 2023 Android のテスト関連セッション Scalable UI testing solutions

    How to test across all screen sizes Pixel Fold やPixel Tablet の登場に合わせて、様々なデバイスに対応 させるためのUI テストの手段が紹介されていた Local Test でのスクリーンショットテストと組み合わせたり、UI テ ストの幅が広がる期待感がありました