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

Snackbar in Compose with Friendly UI Testing

Snackbar in Compose with Friendly UI Testing

A guide to creating and testing Snackbar in Jetpack Compose, with a focus on friendly UI testing.

Avatar for Somkiat Khitwongwattana

Somkiat Khitwongwattana

September 23, 2025
Tweet

More Decks by Somkiat Khitwongwattana

Other Decks in Technology

Transcript

  1. Any Solution? • Remove Snackbar message verification • Create a

    Snackbar controller & container for UI testing
  2. What Controller & Container Do? • Enforce indefinite duration during

    UI testing • Manually dismiss using code in UI testing
  3. SnackbarContainer Recap SnackbarUiTest Controller SnackbarHostState Provider androidTest Store the SnackbarHostState

    that's created while the app is running, so it can be dismissed in a UI test. Inject the SnackbarHostState into the SnackbarUiTestController using Java Reflection Override the duration to be indefinite when running under UI test. main main
  4. Caution • Do not expose your test code to production

    environments, especially in a multi-module project • Avoid unexpected Snackbar behavior in complex UI