Skip to content

Migrate service and UI Automator testing snippets - #1266

Open
rcadeaux wants to merge 1 commit into
android:mainfrom
rcadeaux:rcadeaux/other-components
Open

rcadeaux wants to merge 1 commit into
android:mainfrom
rcadeaux:rcadeaux/other-components

Conversation

@rcadeaux

@rcadeaux rcadeaux commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

This PR migrates 27 Kotlin testing code snippets from the Android services, modern UI Automator, and legacy UI Automator testing documentation guides into :compose:snippets under com.example.compose.snippets.test.othercomponents.

Pages updated:

List of modifications:

  • gradle/libs.versions.toml & compose/snippets/build.gradle.kts: Added androidx.test:rules (libs.androidx.test.rules) and com.google.truth:truth (libs.truth), and updated androidx.test.uiautomator:uiautomator (libs.androidx.test.uiautomator) from 2.3.0 to 2.4.1 so ServiceTestRule and UI Automator snippets compile in androidTest.
  • compose/snippets/src/androidTest/java/com/example/compose/snippets/test/othercomponents/ (ServiceSnippets.kt, UiAutomatorSnippets.kt, and UiAutomatorLegacySnippets.kt): Placed the 3 snippet files in the com.example.compose.snippets.test.othercomponents sub-package so top-level helper declarations (MainActivity, SomeActivity, LocalService) remain isolated from other test snippet files, noted above each androidTest-only helper class that the real component normally lives in src/main, and ran ./gradlew :compose:snippets:spotlessApply to re-indent 2-space blocks to 4-space Kotlin style (including wrapping getLaunchIntentForPackage( in android_testing_other_components_ui_automator_legacy_home_screen).
  • compose/snippets/src/androidTest/java/com/example/compose/snippets/test/othercomponents/UiAutomatorSnippets.kt (android_testing_other_components_ui_automator_lifecycle and android_testing_other_components_ui_automator_permission_watcher): Updated clearAppData("com.example.targetapp") to clearAppData() and startIntent(myIntent) to startActivityIntent(myIntent) to match the UiAutomatorTestScope signatures in androidx.test.uiautomator:uiautomator:2.4.1, commented the printed // import androidx.test.uiautomator.PermissionDialog statement verbatim inside android_testing_other_components_ui_automator_permission_watcher while importing the real androidx.test.uiautomator.watcher.PermissionDialog at the top of the file (flagged for the documentation team to decide whether to update the printed import in the guide page), and added trailing periods to natural-language comments.
  • compose/snippets/src/androidTest/java/com/example/compose/snippets/test/othercomponents/UiAutomatorSnippets.kt (android_testing_other_components_ui_automator_wait_stable and android_testing_other_components_ui_automator_screenshots): Fixed uiautomator { typo to uiAutomator { in android_testing_other_components_ui_automator_screenshots, updated activeWindow() to device.activeWindow() to match UiDevice.activeWindow() in androidx.test.uiautomator:uiautomator:2.4.1, and added trailing periods to natural-language comments. (Note for documentation prose follow-up on /training/testing/other-components/ui-automator: the migration reference table at the bottom of the guide page still lists activeWindow().waitForStable() without the device. receiver, and the Macrobenchmark prose mentions startIntent() instead of startActivityIntent().)
  • compose/snippets/src/androidTest/java/com/example/compose/snippets/test/othercomponents/UiAutomatorSnippets.kt (android_testing_other_components_ui_automator_scope, android_testing_other_components_ui_automator_on_element, android_testing_other_components_ui_automator_on_element_or_null, android_testing_other_components_ui_automator_on_elements, android_testing_other_components_ui_automator_chained, android_testing_other_components_ui_automator_timeout, android_testing_other_components_ui_automator_interact, android_testing_other_components_ui_automator_wait_visible, android_testing_other_components_ui_automator_pip_window, and android_testing_other_components_ui_automator_results_reporter): Added trailing periods to natural-language comments.
  • compose/snippets/src/androidTest/java/com/example/compose/snippets/test/othercomponents/UiAutomatorLegacySnippets.kt (android_testing_other_components_ui_automator_legacy_home_screen and android_testing_other_components_ui_automator_legacy_calculator_setup): Replaced the deprecated androidx.test.runner.AndroidJUnit4 runner with androidx.test.ext.junit.runners.AndroidJUnit4 (both the real import and the commented printed import in android_testing_other_components_ui_automator_legacy_home_screen) without @Suppress("DEPRECATION"), commented printed import statements and ... elision markers with real imports at the top of the file, used null-safe ?.apply on PackageManager.getLaunchIntentForPackage(...) (Intent?) so addFlags(...) compiles, and added trailing periods to natural-language comments.
  • compose/snippets/src/androidTest/java/com/example/compose/snippets/test/othercomponents/UiAutomatorLegacySnippets.kt (android_testing_other_components_ui_automator_legacy_system_clock): Fixed Java variable syntax UiObject2 clock = ... inside the Kotlin block to val clock: UiObject2 = ....
  • compose/snippets/src/androidTest/java/com/example/compose/snippets/test/othercomponents/UiAutomatorLegacySnippets.kt (android_testing_other_components_ui_automator_legacy_calculator_test and android_testing_other_components_ui_automator_legacy_turn_off_dnd): Added trailing periods to natural-language comments.

Snippets not migrated:

  • /training/testing/other-components/content-providers: 1 deprecated ProviderTestCase2 Kotlin snippet (setUp(), left hardcoded on the guide page for a follow-up migration rather than suppressing deprecation warnings or adding legacy android.test.* libraries) and 1 obsolete Java counterpart (setUp()).
  • /training/testing/other-components/services: 2 obsolete Java counterparts (serviceRule and testWithBoundService()).
  • /training/testing/other-components/ui-automator: 2 Gradle dependency configuration snippets (build.gradle.kts and build.gradle androidTestImplementation).
  • /training/testing/other-components/ui-automator-legacy: 2 Gradle dependency configuration snippets, 1 CLI shell invocation ($ uiautomatorviewer), and 11 obsolete Java counterparts (6 in the main guide page and 5 in the included system settings section).

@rcadeaux
rcadeaux requested a review from a team as a code owner November 9, 2026 15:06
@rcadeaux
rcadeaux requested a review from dturner November 9, 2026 15:06
@snippet-bot

snippet-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 27 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@rcadeaux
rcadeaux force-pushed the rcadeaux/other-components branch from ca91aab to d7d6816 Compare November 11, 2026 19:51
@sameng

sameng commented Nov 12, 2026

Copy link
Copy Markdown

Readiness review confirmed:

  • Page is appropriate for migration.
  • Appropriate branch.
  • Correct module.
  • Code matches published page exactly except modifications as described.
  • Valid region and exclude tags.
  • File and region tag match the associated CL.
  • Page has no hardcoded snippets aside from those mentioned in the initial PR comment.
  • PR is open.

Ready for Google review 👍

@rcadeaux
rcadeaux force-pushed the rcadeaux/other-components branch from 8d7af13 to d39b104 Compare November 20, 2026 20:36
@rcadeaux rcadeaux changed the title Migrate content provider, service, and UI Automator testing snippets Migrate service and UI Automator testing snippets Nov 20, 2026
@rcadeaux
rcadeaux force-pushed the rcadeaux/other-components branch from d39b104 to 605c753 Compare November 21, 2026 05:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants