Skip to content

test(utils): add JVM unit and composable integration tests for Clustering and WmsTileOverlay - #1004

Open
dkhawk wants to merge 4 commits into
mainfrom
feature/robolectric-utils-tests
Open

dkhawk wants to merge 4 commits into
mainfrom
feature/robolectric-utils-tests

Conversation

@dkhawk

@dkhawk dkhawk commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Stacked PR on top of #1001 (feature/robolectric-tests).

Adds JVM unit and Jetpack Compose Robolectric integration tests for :maps-compose-utils using the Android Maps Testing Toolkit (com.google.maps.android:maps-testing-robolectric).

Summary of Changes

  • Configured Robolectric Android resource processing (isIncludeAndroidResources = true) and added Compose/Maps Robolectric test dependencies (truth, androidx.test.compose.ui, androidx.test.compose.ui.manifest, androidx.activity.compose, androidx.test.core, maps.testing.robolectric) to maps-compose-utils/build.gradle.kts.
  • Added @Config(sdk = [34]) to ClusterRendererTest.kt for consistent Robolectric SDK execution.
  • Added WmsTileOverlayTest.kt verifying WmsTileOverlay composable rendering, tile overlay attributes (transparency, fadeIn, visible, zIndex), and tile cache clearing.
  • Expanded WmsUrlTileProviderTest.kt covering valid URL string formatting and malformed URL handling.
  • Added ClusteringTest.kt covering:
    • ClusteringMarkerProperties CompositionLocal propagation and mutation.
    • Clustering default renderer clustering and actual rendered cluster/item markers on GoogleMap.
    • Custom Compose UI content rendering (clusterContent, clusterItemContent, clusterItemDecoration) and ClusteringMarkerProperties rotation applied to rendered markers.
    • Dynamic item updates on state change.
    • rememberClusterManager and rememberClusterRenderer lifecycle initialization.

cc @LoyalAbbas @kikoso

@dkhawk
dkhawk requested a review from kikoso September 15, 2026 21:59
@googlemaps-bot

googlemaps-bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 44.43% 🍏

There is no coverage information present for the Files changed

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Coverage (unit tests)

Compared against 92ce5fe on main (#1001).

Module Line % Change Branch % Change
maps-compose 45.85% no change 15.28% no change
maps-compose-utils 74.11% 🔺 +47.82 40.73% 🔺 +28.03
maps-compose-widgets 72.26% no change 40.48% no change
TOTAL 54.03% 🔺 +11.46 21.16% 🔺 +5.54

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

@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch from 7741e9d to b0fbce9 Compare October 1, 2026 21:07

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

Thanks for adding these, @dkhawk ! Can you take a look at the comments? CI is also red, so let's get that green before merging.

Comment thread maps-compose-utils/build.gradle.kts Outdated
Comment on lines +105 to +109
tasks.withType<Test>().configureEach {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(21))
})
}

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.

Could you elaborate on why do we need to force a Java 21 launcher for the tests? If the CI runners don't provide JDK 21 (or toolchain auto-provisioning isn't enabled), this could be what is breaking the build. Would it make sense to align it with the toolchain the rest of the project uses?

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.

Good catch — the Java 21 test launcher override has been removed and maps-compose-utils/build.gradle.kts now uses the same JavaVersion.VERSION_17 / JvmTarget.JVM_17 configuration as the rest of the repo.

Comment thread maps-compose-utils/build.gradle.kts Outdated
Comment on lines +97 to +101
testImplementation(libs.mockk)
testImplementation(libs.androidx.test.compose.ui)
testImplementation(libs.androidx.activity.compose)
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.

I can't see mockk or kotlinx-coroutines-test used in any of the new tests. Should we drop them until we actually need them?

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.

Both mockk and kotlinx-coroutines-test are actively used by ClusterRendererTest.kt (which has since landed on main), so we need to keep both dependencies in maps-compose-utils/build.gradle.kts.

android:name="androidx.activity.ComponentActivity"
android:exported="true" />
</application>
</manifest>

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.

I wonder if we could avoid shipping a debug manifest in the library just for the tests. The androidx.compose.ui:ui-test-manifest artefact registers ComponentActivity for us. What do you think?

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.

Great suggestion — done in 66ddd1fb. Removed maps-compose-utils/src/debug/AndroidManifest.xml and switched to testImplementation(libs.androidx.test.compose.ui.manifest).

Comment on lines +76 to +78
assertThat(tileUrl).isEqualTo(
URL("https://example.com/wms?bbox=-${worldSize},0.0,0.0,${worldSize}&zoom=1")
)

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.

URL.equals() can do host name resolution, which makes this test depend on the network (see the note here). Shouldn't we favour comparing the string representation?

Suggested change
assertThat(tileUrl).isEqualTo(
URL("https://example.com/wms?bbox=-${worldSize},0.0,0.0,${worldSize}&zoom=1")
)
assertThat(tileUrl?.toString()).isEqualTo(
"https://example.com/wms?bbox=-${worldSize},0.0,0.0,${worldSize}&zoom=1"
)

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.

Good catch! Updated in 66ddd1fb to compare tileUrl?.toString() instead of URL.equals() so there's no host resolution.

import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

// [START maps_compose_utils_clustering_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.

Just to understand it: are these [START ...]/[END ...] region tags meant to be pulled into some documentation? If not, I would remove them from the tests.

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 — these [START ...] / [END ...] region tags are used for single-source-of-truth snippet extraction into documentation and guides, consistent with GoogleMapTest, CameraPositionStateTest, and ScaleBarTest.

@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch from b0fbce9 to 8b96198 Compare October 9, 2026 15:32
@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch from 8b96198 to 1d73b07 Compare November 9, 2026 22:00
@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch 2 times, most recently from 6930a05 to a0ebce1 Compare November 10, 2026 23:38
@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch from a0ebce1 to b88dc09 Compare November 17, 2026 20:36
@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch 2 times, most recently from a583af3 to f8e07cf Compare November 17, 2026 23:13
Base automatically changed from feature/robolectric-widgets-tests to feature/robolectric-tests November 24, 2026 20:57
@dkhawk
dkhawk added this pull request to stack #1095 November 24, 2026 21:29
@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch from f8e07cf to 66ddd1f Compare November 24, 2026 21:39
@dkhawk
dkhawk marked this pull request as ready for review November 24, 2026 21:39
@snippet-bot

snippet-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 3 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

@dkhawk
dkhawk requested a review from kikoso November 24, 2026 21:40
@googlemaps-bot

googlemaps-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Coverage (instrumentation tests)

Overall Project 46.14% 🍏

There is no coverage information present for the Files changed

}

@Test
internal fun testClustering_withCustomComposeContent() {

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: we set clusterContent and clusterItemContent here but we never check them, only the decoration. Should we assert on the custom content too, or rename the 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.

Updated in 865eefc5 to assert that clusterContent (4-item cluster), clusterItemContent, and clusterItemDecoration are all invoked and that the rendered markers on GoogleMap receive the 10f and 20f rotations from ClusteringMarkerProperties.

}

@Test
internal fun testClustering_defaultRenderer_rendersItemsAndClusters() {

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.

This one only checks manager.algorithm.items, so we are not testing really that something is rendered. Could we assert on the markers or the clusters as well?

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.

Good catch — updated in 865eefc5 to place 4 nearby SF items + 1 distant NYC item at zoom 4, idle the main looper while waiting for rendering, and assert directly on GoogleMap.markers (hasMarkerCount(2) and hasMarkerWithTitle("NYC")).

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

Looks good to me! Thanks for addressing the comments, @dkhawk . I pushed a fix for the flaky ClusteringTest: inside waitUntil the main looper was never idled, so on a slow runner the clustering result never arrived to the renderer.

@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch from 70f651f to 865eefc Compare December 2, 2026 16:42
Base automatically changed from feature/robolectric-tests to main December 2, 2026 16:58
dkhawk and others added 4 commits December 2, 2026 09:58
- Replace custom debug AndroidManifest.xml with testImplementation(libs.androidx.test.compose.ui.manifest).
- Compare tileUrl?.toString() in WmsUrlTileProviderTest instead of URL.equals() to avoid host resolution.
- Import kotlin.math.PI at top level in WmsUrlTileProviderTest.
- Assert exact updated items in ClusteringTest.testClustering_dynamicItemUpdates.
…lusteringTest

ClusterManager computes clusters on a background dispatcher and delivers
them to the renderer through Dispatchers.Main. Under Robolectric's paused
looper that hand-off only runs when the main looper is idled, and
ComposeTestRule.waitUntil only advances the Compose clock. When clustering
finished after the preceding waitForIdle returned (slow CI runners), the
decoration callback never fired and the test timed out.

Idle the main looper inside the waitUntil condition so the hand-off is
delivered regardless of background timing.
…Test

- Update testClustering_defaultRenderer_rendersItemsAndClusters to use 4 nearby SF items + 1 distant NYC item at zoom 4, idle the main looper, and assert rendered cluster and item markers on GoogleMap.
- Update testClustering_withCustomComposeContent to assert invocations of clusterContent (size-4 cluster), clusterItemContent, and clusterItemDecoration, plus rendered marker rotations (10f and 20f) from ClusteringMarkerProperties.
@dkhawk
dkhawk force-pushed the feature/robolectric-utils-tests branch from 865eefc to 751913d Compare December 2, 2026 16:58

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.

3 participants