Skip to content

test(widgets): add ScaleBar Robolectric tests and migrate GoogleMapTest to KTX helpers - #1001

Merged
dkhawk merged 3 commits into
mainfrom
feature/robolectric-tests
Dec 2, 2026
Merged

dkhawk merged 3 commits into
mainfrom
feature/robolectric-tests

Conversation

@dkhawk

@dkhawk dkhawk commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds JVM unit and Jetpack Compose Robolectric tests for :maps-compose-widgets (ScaleBar and DisappearingScaleBar) and migrates existing :maps-compose GoogleMapTest assertions to the maps-testing-robolectric KTX and Truth helpers.

Changes

  • :maps-compose-widgets: Configure Robolectric Android resources, androidx.test.compose.ui.manifest, and maps-testing-robolectric test dependencies; add ScaleBarTest covering calculateDistance ground-truth assertions, ScaleBar null-projection fallback rendering, and DisappearingScaleBar visibility transitions.
  • :maps-compose: Refactor GoogleMapTest to use createTestMap(), map.markers, map.circles, map.clickMarker(), and GoogleMapSubject.assertThat(map) instead of Shadow.extract/ShadowGoogleMap.

@dkhawk
dkhawk force-pushed the feature/robolectric-tests branch from 0985765 to 34f2003 Compare September 15, 2026 21:09
@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Coverage (unit tests)

Compared against 5a05472 on main (#1099).

Module Line % Change Branch % Change
maps-compose 45.85% no change 15.28% no change
maps-compose-utils 26.29% no change 12.70% no change
maps-compose-widgets 72.26% 🔺 +68.39 40.48% 🔺 +40.48
TOTAL 42.57% 🔺 +3.62 15.62% 🔺 +1.36

Line and branch coverage from unit test reports. History is recorded on the coverage-history branch after each merge to main.

@googlemaps-bot

googlemaps-bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 44.45% 🍏

There is no coverage information present for the Files changed

@dkhawk
dkhawk requested a review from kikoso September 15, 2026 21:59
@dkhawk
dkhawk force-pushed the feature/robolectric-tests branch from 34f2003 to 57c2723 Compare October 1, 2026 21:07
@dkhawk
dkhawk force-pushed the feature/robolectric-tests branch from 57c2723 to a63c557 Compare October 9, 2026 15:32
@dkhawk
dkhawk force-pushed the feature/robolectric-tests branch from a63c557 to 1a8f666 Compare November 9, 2026 22:00
@dkhawk dkhawk changed the title test: add JVM unit and composable integration tests using android-maps-robolectric test: add JVM unit and composable integration tests using Android Maps Testing Toolkit Nov 10, 2026
@dkhawk
dkhawk force-pushed the feature/robolectric-tests branch 2 times, most recently from df2a0d9 to ee29efc Compare November 10, 2026 23:38
@dkhawk
dkhawk force-pushed the feature/robolectric-tests branch 2 times, most recently from 5dcab93 to 6134e13 Compare November 17, 2026 23:13
@dkhawk
dkhawk marked this pull request as ready for review November 24, 2026 20:07
@snippet-bot

snippet-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

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

@dkhawk
dkhawk force-pushed the feature/robolectric-tests branch from 32bc253 to f217943 Compare November 24, 2026 21:02
@googlemaps-bot

googlemaps-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Coverage (instrumentation tests)

Overall Project 46.18% 🍏

There is no coverage information present for the Files changed

@dkhawk
dkhawk added this pull request to stack #1095 November 24, 2026 21:29
@dkhawk

dkhawk commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

@kikoso This is ready for a fresh review — #1003 (with your ScaleBarTest feedback addressed) has been merged into this branch, and the PR is now cleanly rebased onto main with conflicts resolved (f217943e).

-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in maps-compose we get this activity from libs.androidx.test.compose.ui.manifest. Could we delete this file and add the same dependency as testImplementation in the widgets module? I tried it locally and ScaleBarTest keeps passing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 50602e48 — deleted maps-compose-widgets/src/debug/AndroidManifest.xml and switched to testImplementation(libs.androidx.test.compose.ui.manifest). All :maps-compose-widgets unit tests pass.

Comment thread maps-compose-widgets/build.gradle.kts Outdated
Comment on lines +120 to +121
testImplementation(libs.androidx.test.core)
testImplementation(libs.kotlinx.coroutines.test)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: androidx.test.core and kotlinx-coroutines-test are not used anywhere in the widgets tests, I think we can remove both.

Suggested change
testImplementation(libs.androidx.test.core)
testImplementation(libs.kotlinx.coroutines.test)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed both unused dependencies (androidx.test.core and kotlinx-coroutines-test) in 50602e48 — :maps-compose-widgets:testDebugUnitTest and lint remain green.

}

composeTestRule.waitForIdle()
composeTestRule.onNodeWithText("0 ft").assertIsDisplayed()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to understand it: the state is never attached to a map, so the projection is null and we render always the 0 fallback, right? Would it make sense to add a comment here, so nobody thinks we are checking a real label?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly — cameraState isn't attached to a GoogleMap in that test, so projection is null and ScaleBar renders the 0 fallback labels. Added an explicit comment in 50602e48 to make that clear (and I'm adding live GoogleMap-bound ScaleBar and adversarial edge-case tests in a follow-up PR).

@kikoso kikoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @dkhawk . Could we update the title and description before merging? After the rebase most of the tests listed there are already in main, and the squash commit will take the title.

@dkhawk dkhawk changed the title test: add JVM unit and composable integration tests using Android Maps Testing Toolkit test(widgets): add ScaleBar Robolectric tests and migrate GoogleMapTest to KTX helpers Nov 25, 2026
* test(widgets): add JVM unit and composable tests for ScaleBar

* test(widgets): address review feedback in ScaleBarTest

- Assert calculateDistance against known ground-truth values (mocked equatorial span = 98m, plus Mercator zoom 12 checks at 0 deg and 60 deg latitude) instead of repeating the implementation formula.
- Remove unused sphericalDistance import from ScaleBarTest.
- Add displayed text assertions in ScaleBar test and mainClock-driven show/hide/re-show/hide assertions in DisappearingScaleBar test.
- Delete maps-compose-widgets/src/debug/AndroidManifest.xml and use testImplementation(libs.androidx.test.compose.ui.manifest).
- Remove unused androidx.test.core and kotlinx-coroutines-test dependencies from maps-compose-widgets/build.gradle.kts.
- Document null-projection fallback behavior in ScaleBarTest.
@dkhawk
dkhawk merged commit 92ce5fe into main Dec 2, 2026
14 of 15 checks passed
@dkhawk
dkhawk deleted the feature/robolectric-tests branch December 2, 2026 16:58
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.

3 participants