Migrate Compose tests off deprecated createComposeRule (#1792)#1941
Merged
Conversation
Six on-device Compose tests used the deprecated v1
`androidx.compose.ui.test.junit4.createComposeRule` behind a
`@Suppress("DEPRECATION")`, because the v2 rule's default
`StandardTestDispatcher` broke the `onGloballyPositioned` ->
`LaunchedEffect` -> `animateScrollTo` chains in EtaStrip/SlideBox when
#1792 was filed.
Route all six through a shared `createUnconfinedComposeRule()` helper
that calls the non-deprecated `v2.createComposeRule(...)` and pins
composition to an `UnconfinedTestDispatcher` via its `effectContext`
parameter, reproducing the old eager-execution semantics without any
deprecation suppression.
Investigated the original blocker: on the current stack
(compose-ui-test 1.11.4) plain v2 with StandardTestDispatcher now passes
all six tests on-device too — the rule's reworked waitUntil/idle
machinery pumps the dispatcher — so there is no upstream bug left to
file. Unconfined is retained only because SlideBoxTest is an @smoketest
on the API 23 floor emulator whose StandardTestDispatcher timing is
unvalidated.
Also correct a stale BOM version comment in build.gradle.kts
(2026.05.00/1.11.2 -> 2026.06.01/1.11.4).
Verified: androidTest compiles clean under -PwarningsAsErrors=true, and
all 12 tests across the six classes pass on-device (Pixel 7 Pro).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughA shared unconfined Compose test rule was added and adopted by six instrumentation tests. Deprecated rule suppressions and imports were removed, while the Compose UI BOM version comment was updated from 1.11.2 to 1.11.4. ChangesCompose test rule migration
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1792.
What
Six on-device Compose tests used the deprecated v1
androidx.compose.ui.test.junit4.createComposeRulebehind a@Suppress("DEPRECATION"). This routes all six through a new shared helper and removes every suppression:The v2
createComposeRule(effectContext)uses anyTestDispatcherfound ineffectContextfor composition and theMainTestClock, so passingUnconfinedTestDispatcher()reproduces the old v1 eager-execution semantics on the supported API — no behavior change, no deprecation suppression. No new dependencies (kotlinx-coroutines-testwas already anandroidTestImplementationdep).Migrated files:
ui/arrivals/EtaStripJustifyTest.ktui/compose/components/SlideBoxTest.kt(@SmokeTest)ui/arrivals/ArrivalAlertIndicatorTest.ktui/arrivals/RouteArrivalRowLongPressTest.ktui/home/map/FocusBannerTest.ktui/home/arrivals/ServiceAlertsDialogTest.ktThe investigation #1792 asked for
The original blocker was that the v2 rule's default
StandardTestDispatcherqueues composition coroutines rather than running them eagerly, and theonGloballyPositioned→LaunchedEffect→animateScrollTochains inEtaStrip/SlideBoxnever advanced under it.I re-characterized this on the current stack (compose-ui-test 1.11.4, BOM 2026.06.01): plain v2 with
StandardTestDispatchernow passes all six tests on-device too. 1.11.4's reworkedwaitUntil/idle machinery actively pumps the dispatcher (runCurrent()+advanceTimeByFrame()), which the BOM at filing time did not — so the breakage was an upstream compose-ui-test gap that has since been fixed. There is no upstream bug left to file.I still pin
UnconfinedTestDispatcherbecauseSlideBoxTestruns as an@SmokeTeston the API 23 floor emulator, whoseStandardTestDispatcherframe/animation timing hasn't been validated. Unconfined keeps the eager-execution contract the smoke floor relies on. A future switch to the plain default is low-risk but should be checked on the floor emulator first — the helper KDoc documents this.Also
Corrected a stale BOM version comment in
build.gradle.kts(2026.05.00/1.11.2→ the catalog's actual2026.06.01/1.11.4).Verification
./gradlew :onebusaway-android:compileObaGoogleDebugAndroidTestKotlin -PwarningsAsErrors=true— clean.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests