Skip to content

Migrate Libraries and tools to test different screen sizes snippets - #1249

Open
rcadeaux wants to merge 1 commit into
android:mainfrom
rcadeaux:rcadeaux/different-screens-tools
Open

rcadeaux wants to merge 1 commit into
android:mainfrom
rcadeaux:rcadeaux/different-screens-tools

Conversation

@rcadeaux

@rcadeaux rcadeaux commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Code snippets are for:

The Espresso Device test snippets (android_compose_testing_different_screens_espresso_device_tabletop and android_compose_testing_different_screens_requires_device_mode) and the Window Testing Views snippet (android_compose_testing_different_screens_window_testing_views) on the guide page reference R.id.player and R.id.media_controls inside onView(withId(...)) assertions and will not compile without those view ID resources. Two <item type="id" /> entries (media_controls and player) were added in a standalone values resource file (compose/snippets/src/main/res/values/different_screens_ids.xml) outside any snippet region so the Kotlin snippets compile without modifying any existing snippet file.

List of modifications:

  • Tools page: Extracted 14 Kotlin testing snippets into compose/snippets/src/androidTest/java/com/example/compose/snippets/test/differentscreens/DifferentScreensToolsSnippets.kt (isolated in the com.example.compose.snippets.test.differentscreens sub-package so top-level test helper classes such as MainActivity do not collide with sibling testing pages):
    • android_compose_testing_different_screens_device_configuration_override (DeviceConfigurationOverride.ForcedSize Compose test)
    • android_compose_testing_different_screens_robolectric_config (@Config(qualifiers = "w1000dp-h1000dp-480dpi") Robolectric screenshot test class)
    • android_compose_testing_different_screens_robolectric_set_qualifiers (RuntimeEnvironment.setQualifiers Robolectric test snippet)
    • android_compose_testing_different_screens_width_annotations (@TestExpandedWidth and @TestCompactWidth custom annotations)
    • android_compose_testing_different_screens_filtered_test_class (MyTestClass using @TestExpandedWidth and @TestCompactWidth)
    • android_compose_testing_different_screens_espresso_device_tabletop (onDevice().setTabletopMode() Espresso Device test)
    • android_compose_testing_different_screens_requires_device_mode (@RequiresDeviceMode annotations with TABLETOP and BOOK)
    • android_compose_testing_different_screens_requires_display (@RequiresDisplay(EXPANDED, COMPACT) annotation test)
    • android_compose_testing_different_screens_resize_display_compact (onDevice().setDisplaySize(WidthSizeClass.COMPACT, HeightSizeClass.COMPACT) test)
    • android_compose_testing_different_screens_resize_display_expanded (onDevice().setDisplaySize(WidthSizeClass.EXPANDED, HeightSizeClass.EXPANDED) test)
    • android_compose_testing_different_screens_state_restoration_tester (StateRestorationTester.emulateSavedInstanceStateRestore() Compose test)
    • android_compose_testing_different_screens_foldable_preview (@Preview composable using FoldingFeature from androidx.window.testing.layout)
    • android_compose_testing_different_screens_window_testing_compose (MediaControlsFoldingFeatureTest foldable test with Compose)
    • android_compose_testing_different_screens_window_testing_views (MediaControlsFoldingFeatureTest foldable test with Views)
  • Tools page: Wrapped the same-line class-body ellipsis class NiaAppScreenSizesScreenshotTests { ... } in android_compose_testing_different_screens_robolectric_config and the same-line destructuring declaration ellipsis val (width, height, dpi) = ... in android_compose_testing_different_screens_robolectric_set_qualifiers in [START_EXCLUDE silent] block-comment twins backed by compiling declarations (class NiaAppScreenSizesScreenshotTests and val (width, height, dpi) = Triple(1000, 1000, 480)) so the rendered output matches the guide page verbatim. Because { ... } (a class body) and = ... (a destructuring declaration) carry no explicit declared type or provenance comment, this pattern is noted here so the docs team can confirm it.
  • Tools page: Commented out the 5 instructional import lines inside android_compose_testing_different_screens_window_testing_compose and the 5 instructional import lines inside android_compose_testing_different_screens_window_testing_views (// import androidx.window...) because Kotlin only permits import directives at the top of a file, while the real imports are declared at the file header so the code compiles.
  • Tools page: Applied ./gradlew :compose:snippets:spotlessApply formatting while preserving @Composable private fun FoldablePreview() = on a single line to match the guide page.
  • Tools page: Added androidx.test.espresso:espresso-device and androidx.window:window-testing to gradle/libs.versions.toml, and added libs.androidx.test.espresso.device, libs.androidx.test.ext.junit.ktx, libs.androidx.window.testing, and libs.robolectric to compose/snippets/build.gradle.kts (alphabetized) so all testing APIs resolve.
  • Tools page: Added <item name="media_controls" type="id" /> and <item name="player" type="id" /> in compose/snippets/src/main/res/values/different_screens_ids.xml outside any snippet region. Required for the Kotlin snippets to compile.

Snippets not migrated:

  • Line 67 (android { testOptions { managedDevices { devices { ... } } } }) because it is a Gradle Managed Devices configuration block in build.gradle rather than Kotlin source code.
  • Line 128 ($ ./gradlew pixelTabletApi30DebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation='com.sample.TestExpandedWidth') because it is a command-line shell command.
  • Line 136 ($ ./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation='com.sample.TestExpandedWidth') because it is a command-line shell command.

@rcadeaux
rcadeaux requested a review from a team as a code owner November 3, 2026 22:47
@rcadeaux
rcadeaux requested a review from bsagmoe November 3, 2026 22:47
@snippet-bot

snippet-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 14 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/different-screens-tools branch from fad1b16 to b2586a2 Compare November 11, 2026 19:23
@rcadeaux
rcadeaux force-pushed the rcadeaux/different-screens-tools branch from 0782548 to be4b8b6 Compare November 21, 2026 06:41

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.

1 participant