Skip to content

Add Roborazzi screenshot / golden UI testing - #223

Open
dipenpradhan wants to merge 26 commits into
Gurupreet:masterfrom
dipenpradhan:issue-201-roborazzi
Open

Add Roborazzi screenshot / golden UI testing#223
dipenpradhan wants to merge 26 commits into
Gurupreet:masterfrom
dipenpradhan:issue-201-roborazzi

Conversation

@dipenpradhan

Copy link
Copy Markdown

Summary

Adds screenshot / golden UI testing with Roborazzi, as proposed in #201. Roborazzi renders Compose under Robolectric on the JVM, so screenshot tests run in plain unit-test infrastructure — no emulator or connected device required, and they work in the existing ./gradlew CI.

What's included

  • Roborazzi + Robolectric added to the version catalog (roborazzi 1.46.1, robolectric 4.14.1) with a screenshot-test bundle and a plugin alias
  • The io.github.takahirom.roborazzi plugin applied to :components:tags (a small, deterministic module — no animations/Lottie), with testOptions.unitTests.isIncludeAndroidResources = true
  • InterestTagScreenshotTest: golden tests for a single tag and a row of tags, pinned to a fixed device qualifier (w360dp-h640dp) for stable output
  • Committed golden PNGs under components/tags/src/test/screenshots/

Workflow

  • Record / refresh goldens: ./gradlew :components:tags:recordRoborazziDebug
  • Verify against goldens: ./gradlew :components:tags:verifyRoborazziDebug

The default ./gradlew test / build runs the tests in capture mode (writes images, always green); explicit visual regression is the opt-in verifyRoborazzi* task, which a maintainer can wire into CI as a follow-up.

Scope note

This establishes the screenshot-testing pattern on one curated module (as #201 suggests — "a small curated set of screens"). Rolling it out to more showcase screens is straightforward follow-up; suggest keeping #201 open until that broader coverage lands.

Verification

  • ./gradlew :components:tags:recordRoborazziDebug generates the goldens; :components:tags:verifyRoborazziDebug passes against them (JDK 17, JVM/Robolectric — no emulator)
  • ./gradlew ktfmtCheck assembleDebug testDebugUnitTest passes locally
  • CI ./gradlew build on this PR

Merge order

Stacks on #222 and the rest of the chain. Its diff includes those commits until they merge.

Refs #201

🤖 Generated with Claude Code

cc @Gurupreet for review

- Bump kotlin-gradle-plugin 1.9.22 -> 2.1.20 (root + buildSrc)
- Adopt the new Compose Compiler Gradle plugin
  (org.jetbrains.kotlin.plugin.compose) in app and convention plugins
- Drop composeCompiler version constant and composeOptions blocks
- Replace removed -Xopt-in flag with -opt-in
- Bump KSP to 2.1.20-1.0.31 to match Kotlin

Fixes Gurupreet#182
ktfmt-gradle 0.12.0 fails with 'Generic error during file processing'
once Kotlin 2.x is on the buildscript classpath. 0.22.0 supports
Kotlin 2.x and also formats *.kts build scripts, hence the repo-wide
reformat (no functional changes).
- AGP 8.2.2 -> 8.7.3 (compileSdk 35 supported from AGP 8.6)
- Gradle wrapper 8.5 -> 8.9 (required by AGP 8.7.x)
- PinLockView: removeLast() -> removeAt(lastIndex); at compileSdk 35 the
  call binds to java.util.List#removeLast (API 35) instead of the Kotlin
  stdlib extension, failing lint NewApi against minSdk 25

Fixes Gurupreet#185
- Replace compose/material3 version constants with composeBom
- Strip explicit versions from BOM-managed artifacts
- Import the BOM platform on every configuration that receives
  Compose artifacts (implementation, debugImplementation,
  androidTestImplementation, :data)
- Migrate API removals that come with Compose 1.7 / Material3 1.3:
  SmallTopAppBar -> TopAppBar, rememberRipple -> material3 ripple
- Update the outdated README Compose badge to the BOM version

Fixes Gurupreet#186
All lifecycle artifacts (viewmodel-compose, viewmodel-ktx,
livedata-ktx, runtime-ktx, viewmodel-savedstate) move together
via the shared androidLifecycleGrouped version.

Fixes Gurupreet#192
- navCompose 2.7.7 -> 2.8.9; add kotlinx-serialization-json 1.8.0
- Apply the Kotlin serialization plugin in gmail and tiktok demos
- Gmail: string routes -> @serializable route objects
- TikTok: TikTokScreen becomes a serializable sealed interface;
  the profile route carries a typed userId argument read via
  toRoute(), bottom bar selection uses NavDestination.hasRoute

Fixes Gurupreet#193
- Replace com.google.android.exoplayer:exoplayer with
  androidx.media3:media3-exoplayer and media3-ui
- Rewrite TikTokPlayer against the Media3 API (SimpleExoPlayer was
  removed; default media source factory handles asset URIs)
- Removes the last Jetifier warning produced by ExoPlayer 2.x

Fixes Gurupreet#183
- Move to the io.coil-kt.coil3 artifact group
- Add coil-network-okhttp (network fetching is a separate artifact
  in Coil 3, self-registered via ServiceLoader)
- Migrate call sites: rememberImagePainter(data=) ->
  rememberAsyncImagePainter(model=), coil.* -> coil3.* imports

Fixes Gurupreet#191
PullRefreshList was a fully commented-out stub (TODO revisit pull
refresh). It now demonstrates the first-party PullToRefreshBox with
a simulated 1.5s reload that prepends an item to the list.

Fixes Gurupreet#187
Covers the new composables added here so the feature ships with its own
verification rather than relying on a later change in the stack.
…undo

The Swipeable Lists tab rendered SwipeToDismissBox items but swipes
never removed anything. Now:
- swipe left deletes (red background), swipe right archives
- items are actually removed from the keyed LazyColumn
- an Undo snackbar restores the item at its original position
- positionalThreshold set to half the item width

Fixes Gurupreet#188
Adds UI tests for the composables introduced here so the feature ships with
its own verification.

The undo test surfaced a real defect: tapping Undo re-added the album to the
backing list, but LazyColumn keeps the first visible item anchored, so a row
re-inserted above it silently landed off-screen and the user saw nothing
happen. The list now holds a LazyListState and scrolls the restored row back
into view.
- NavigationSuiteScaffold switches bottom bar / rail / drawer by
  window size class
- ListDetailPaneScaffold gives single-pane on phones, two-pane on
  tablets and foldables, with predictive-back-aware pane navigation
- Favorites/Profile destinations display the live window size classes
- All adaptive artifacts are version-managed by the Compose BOM

Fixes Gurupreet#190
Covers the new composables added here so the feature ships with its own
verification rather than relying on a later change in the stack.
InfiniteCarousel builds on foundation's HorizontalPager with a large
virtual page count starting in the middle, so it loops endlessly in
both directions. Auto-advances every 3s and pauses while dragging.
Showcased at the top of the Carousel demo screen.

Fixes Gurupreet#13
Adds InfiniteCarouselTest so the carousel ships with its own verification
instead of relying on a later change in the stack. The convention plugin now
sets testInstrumentationRunner so library modules can host androidTests.

Swipe gestures target the root rather than the Text node inside a page: a
gesture is dispatched over the bounds of the node it is performed on, and a
Text node is far too narrow to cross the pager's paging threshold.
- InterestTagTest: text, click action, onClick callback
- LoginScreenTest: fields, button, text input

The carousel's test ships alongside the carousel itself, so this change covers
the components that already existed without any test coverage.

Refs Gurupreet#68
- gradle/libs.versions.toml is the single source of truth for all
  versions, libraries and plugins; bundles mirror the old grouped
  dependency helpers
- All module build files use libs.* accessors
- Root build script uses the plugins DSL (ktfmt via alias); AGP,
  Kotlin, KSP and serialization reach the classpath via buildSrc,
  whose own dependencies are catalog-driven through a new
  buildSrc/settings.gradle.kts
- Delete Versions.kt, Dependencies.kt, GroupedDependencies.kt and
  DependencyHandlerExtensions.kt; keep convention plugins and
  ProjectConfigs.kt

Fixes Gurupreet#189
activity-compose 1.10.1, core-ktx 1.16.0, appcompat 1.7.1,
material 1.12.0, room 2.7.1, paging 3.3.6, coroutines 1.10.2,
retrofit 2.11.0. Versions newer than these require compileSdk 36
and are deferred.

Fixes Gurupreet#199
PredictiveBackActivity uses Compose's PredictiveBackHandler to drive
an in-app drawer that follows the back-swipe progress (translate +
scale + fade), commits closed on completion and springs back on
cancel. Adds enableOnBackInvokedCallback to the manifest.

Fixes Gurupreet#200
Covers the new composables added here so the feature ships with its own
verification rather than relying on a later change in the stack.
ContrastThemeActivity shows Standard/Medium/High M3 contrast levels
with runtime switching via a segmented button, in light and dark.
On Android 14+ the initial level reads UiModeManager.getContrast().

Fixes Gurupreet#202
Covers the new composables added here so the feature ships with its own
verification rather than relying on a later change in the stack.
SharedElementActivity uses SharedTransitionLayout + AnimatedContent
to animate album art and title between a list row and a detail
header via sharedElement keys.

Fixes Gurupreet#203
Covers the new composables added here so the feature ships with its own
verification rather than relying on a later change in the stack.
- Add roborazzi 1.46.1 + robolectric 4.14.1 to the version catalog
  (screenshot-test bundle + plugin alias)
- Apply the roborazzi plugin to :components:tags with
  includeAndroidResources; capture composables directly (no host
  Activity) so tests run on the JVM with no emulator
- InterestTagScreenshotTest with committed golden PNGs

Record: ./gradlew :components:tags:recordRoborazziDebug
Verify: ./gradlew :components:tags:verifyRoborazziDebug

Refs Gurupreet#201
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