Repository navigation
Conversation
Code Coverage
|
Coverage (unit tests)Compared against
Line and branch coverage from unit test reports. History is recorded on the |
7741e9d to
b0fbce9
Compare
| tasks.withType<Test>().configureEach { | ||
| javaLauncher.set(javaToolchains.launcherFor { | ||
| languageVersion.set(JavaLanguageVersion.of(21)) | ||
| }) | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| testImplementation(libs.mockk) | ||
| testImplementation(libs.androidx.test.compose.ui) | ||
| testImplementation(libs.androidx.activity.compose) | ||
| testImplementation(libs.androidx.test.core) | ||
| testImplementation(libs.kotlinx.coroutines.test) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Great suggestion — done in 66ddd1fb. Removed maps-compose-utils/src/debug/AndroidManifest.xml and switched to testImplementation(libs.androidx.test.compose.ui.manifest).
| assertThat(tileUrl).isEqualTo( | ||
| URL("https://example.com/wms?bbox=-${worldSize},0.0,0.0,${worldSize}&zoom=1") | ||
| ) |
There was a problem hiding this comment.
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?
| 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" | |
| ) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
b0fbce9 to
8b96198
Compare
8b96198 to
1d73b07
Compare
6930a05 to
a0ebce1
Compare
a0ebce1 to
b88dc09
Compare
a583af3 to
f8e07cf
Compare
f8e07cf to
66ddd1f
Compare
|
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
Coverage (instrumentation tests)
|
| } | ||
|
|
||
| @Test | ||
| internal fun testClustering_withCustomComposeContent() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
70f651f to
865eefc
Compare
…ring and WmsTileOverlay
- 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.
865eefc to
751913d
Compare
Description
Stacked PR on top of #1001 (
feature/robolectric-tests).Adds JVM unit and Jetpack Compose Robolectric integration tests for
:maps-compose-utilsusing the Android Maps Testing Toolkit (com.google.maps.android:maps-testing-robolectric).Summary of Changes
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) tomaps-compose-utils/build.gradle.kts.@Config(sdk = [34])toClusterRendererTest.ktfor consistent Robolectric SDK execution.WmsTileOverlayTest.ktverifyingWmsTileOverlaycomposable rendering, tile overlay attributes (transparency,fadeIn,visible,zIndex), and tile cache clearing.WmsUrlTileProviderTest.ktcovering valid URL string formatting and malformed URL handling.ClusteringTest.ktcovering:ClusteringMarkerPropertiesCompositionLocalpropagation and mutation.Clusteringdefault renderer clustering and actual rendered cluster/item markers onGoogleMap.clusterContent,clusterItemContent,clusterItemDecoration) andClusteringMarkerPropertiesrotation applied to rendered markers.rememberClusterManagerandrememberClusterRendererlifecycle initialization.cc @LoyalAbbas @kikoso