Skip to content

Migrate Compose tests off deprecated createComposeRule (#1792)#1941

Merged
bmander merged 1 commit into
mainfrom
fix/1792-compose-test-rule-v2
Jul 18, 2026
Merged

Migrate Compose tests off deprecated createComposeRule (#1792)#1941
bmander merged 1 commit into
mainfrom
fix/1792-compose-test-rule-v2

Conversation

@bmander

@bmander bmander commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Closes #1792.

What

Six on-device Compose tests used the deprecated v1 androidx.compose.ui.test.junit4.createComposeRule behind a @Suppress("DEPRECATION"). This routes all six through a new shared helper and removes every suppression:

@OptIn(ExperimentalCoroutinesApi::class)
fun createUnconfinedComposeRule(): ComposeContentTestRule =
    createComposeRule(UnconfinedTestDispatcher())   // the non-deprecated v2 rule

The v2 createComposeRule(effectContext) uses any TestDispatcher found in effectContext for composition and the MainTestClock, so passing UnconfinedTestDispatcher() reproduces the old v1 eager-execution semantics on the supported API — no behavior change, no deprecation suppression. No new dependencies (kotlinx-coroutines-test was already an androidTestImplementation dep).

Migrated files:

  • ui/arrivals/EtaStripJustifyTest.kt
  • ui/compose/components/SlideBoxTest.kt (@SmokeTest)
  • ui/arrivals/ArrivalAlertIndicatorTest.kt
  • ui/arrivals/RouteArrivalRowLongPressTest.kt
  • ui/home/map/FocusBannerTest.kt
  • ui/home/arrivals/ServiceAlertsDialogTest.kt

The investigation #1792 asked for

The original blocker was that the v2 rule's default StandardTestDispatcher queues composition coroutines rather than running them eagerly, and the onGloballyPositionedLaunchedEffectanimateScrollTo chains in EtaStrip/SlideBox never advanced under it.

I re-characterized this on the current stack (compose-ui-test 1.11.4, BOM 2026.06.01): plain v2 with StandardTestDispatcher now passes all six tests on-device too. 1.11.4's reworked waitUntil/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 UnconfinedTestDispatcher because SlideBoxTest runs as an @SmokeTest on the API 23 floor emulator, whose StandardTestDispatcher frame/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 actual 2026.06.01/1.11.4).

Verification

  • ./gradlew :onebusaway-android:compileObaGoogleDebugAndroidTestKotlin -PwarningsAsErrors=true — clean.
  • On-device (Pixel 7 Pro / Android 16): all 12 tests across the six classes pass under the shipped Unconfined config; also verified passing under plain v2 during the investigation.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved the reliability and timing consistency of Compose-based UI tests.
  • Tests

    • Updated UI tests to use an eager, unconfined test execution mode.
    • Preserved existing coverage for arrival alerts, route rows, arrival displays, dialogs, maps, and interactive components.
    • Added shared test support for consistent Compose coroutine behavior.

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>
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a4c22b5-81f2-4652-90de-92bd650b77aa

📥 Commits

Reviewing files that changed from the base of the PR and between f3bd405 and ff42276.

📒 Files selected for processing (8)
  • onebusaway-android/build.gradle.kts
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/arrivals/ArrivalAlertIndicatorTest.kt
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/arrivals/EtaStripJustifyTest.kt
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/arrivals/RouteArrivalRowLongPressTest.kt
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/compose/ComposeTestRules.kt
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/compose/components/SlideBoxTest.kt
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/home/arrivals/ServiceAlertsDialogTest.kt
  • onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/home/map/FocusBannerTest.kt

📝 Walkthrough

Walkthrough

A 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.

Changes

Compose test rule migration

Layer / File(s) Summary
Shared unconfined rule and test adoption
onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/compose/ComposeTestRules.kt, onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/{arrivals,home}/**, onebusaway-android/src/androidTest/java/org/onebusaway/android/ui/compose/components/SlideBoxTest.kt
Adds createUnconfinedComposeRule() using UnconfinedTestDispatcher and updates six Compose tests to use it instead of the deprecated rule factory.
Compose version annotation
onebusaway-android/build.gradle.kts
Updates the documented Compose UI version from 1.11.2 via BOM to 1.11.4 via BOM without changing BOM wiring.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The build.gradle.kts Compose BOM comment update is unrelated to the EtaStripJustifyTest migration requested by #1792. Move the Compose BOM comment/version tweak into a separate PR or justify it as required for the migration.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the Compose test migration away from deprecated createComposeRule.
Linked Issues check ✅ Passed The PR migrates EtaStripJustifyTest to the new Compose rule and removes its deprecation suppression, matching #1792's core requirement.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1792-compose-test-rule-v2

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@bmander
bmander merged commit 587d4bd into main Jul 18, 2026
3 checks passed
@bmander
bmander deleted the fix/1792-compose-test-rule-v2 branch July 18, 2026 06:39
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.

Migrate EtaStripJustifyTest off deprecated createComposeRule (v2 breaks onGloballyPositioned dispatch)

1 participant