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

Compose で手に入れた UI の Unit test

mkeeda
March 10, 2023

Compose で手に入れた UI の Unit test

Android Test Night #8 で話したスライド
https://testnight.connpass.com/event/274733/

mkeeda

March 10, 2023
Tweet

More Decks by mkeeda

Other Decks in Programming

Transcript

  1. Compose UI Unit test 2 02 3 / 03 /

    10 Android Test Night # 8 mkeeda
  2. About me • mkeeda (޲Ҫా Ұฏ) • Twitter: @mr_mkeeda •

    Github: @mkeeda • Android Engineer at Cybozu, Inc 2
  3. Domain Layer UI Layer Data Layer 4 UI elements State

    holders UseCases Repositories DataSources ViewModelTest UseCaseTest RepositoryTest DatabaseTest, NetworkTest
  4. End-to-end test 5 Domain Layer UI Layer Data Layer UI

    elements State holders UseCases Repositories DataSources Espresso performAction() & assert() 😍 🤮 🤮
  5. 6 Domain Layer UI Layer Data Layer UI elements State

    holders UseCases Repositories DataSources Unit test : UI ViewModel 
 or Fake 🤮 😍 😍
  6. UI Unit test UI 
 disable 7 Domain Layer UI

    Layer Data Layer UI elements State holders UseCases Repositories DataSources
  7. Jetpack Compose UI f(UI state) = UI 8 @Preview @Composable

    fun IntTextFieldPreview() { Surface { IntTextField( value = 0, onValueChange = {} ) } }
  8. Compose UI 9 @Test fun `੔਺Ҏ֎͸ೖྗͰ͖ͳ͍`() = runComposeUiTest { var

    userInputText: Int? by mutableStateOf(0) setContent { IntTextField( value = userInputText, onValueChange = { userInputText = it } ) } val notInt = "sample" onNode(hasSetTextAction()).performTextInput(notInt) onNodeWithText(notInt).assertDoesNotExist() assertThat(userInputText).isEqualTo(0) } ComposeTestRule 
 UI
  9. Android class ⾒ Local test with Robolectric (AndroidView) My app

    Robolectric ShadowView MyView Local JVM Espresso performAction() & assert()
  10. Instrumented test (Compose) 16 Compose test library performAction() & assert()

    My app Android framework android.graphic.Canvas MyComposable Android Runtime Compose Runtime
  11. Semantic assert Shadow Local test with Robolectric (Compose) 17 Compose

    test library performAction() & assert() My app Robolectric ShadowCanvas MyComposable Local JVM Compose Runtime