Skip to content

test(widgets): add JVM unit and composable tests for ScaleBar - #1003

Draft
dkhawk wants to merge 1 commit into
feature/robolectric-testsfrom
feature/robolectric-widgets-tests
Draft

dkhawk wants to merge 1 commit into
feature/robolectric-testsfrom
feature/robolectric-widgets-tests

Conversation

@dkhawk

@dkhawk dkhawk commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Description

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

Introduces JVM unit and Compose integration tests using Robolectric and the local shadow library for maps-compose-widgets, bringing module line coverage up from 0.00% to 67.12% (instruction coverage from 0.00% to 80.68%).

Summary of Changes

  • Added test dependencies (robolectric, mockk, truth, androidx.test.compose.ui, maps.robolectric.shadows) in maps-compose-widgets/build.gradle.kts.
  • Configured Robolectric Android resources and Java 21 test runner toolchain.
  • Added debug manifest with ComponentActivity for Robolectric Compose rule hosting.
  • Added ScaleBarTest.kt covering canvas distance calculation, unit conversions (ft, mi), ScaleBar composable rendering, and DisappearingScaleBar camera position animation/state changes.

cc @LoyalAbbas @kikoso

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Coverage (unit tests)

Compared against cb74115 on feature/robolectric-tests (#1031).

Module Line % Change Branch % Change
maps-compose 36.95% 🔺 +36.95 10.42% 🔺 +10.42
maps-compose-utils 2.04% no change 0.49% no change
maps-compose-widgets 67.12% 🔺 +67.12 52.94% 🔺 +52.94
TOTAL 31.50% 🔺 +31.09 9.89% 🔺 +9.80

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

@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.45% 🍏

There is no coverage information present for the Files changed

@dkhawk
dkhawk force-pushed the feature/robolectric-widgets-tests branch from 9f260d3 to bab4d05 Compare October 1, 2026 21:07
@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-widgets-tests branch from bab4d05 to d74586e Compare October 9, 2026 15:32

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

Minor comments @dkhawk , but looks good! The instrumentation failure is the emulator not starting in maps-app (adb could not connect), unrelated to this PR, so a rerun should do.


val expectedDistance = startLatLng.sphericalDistance(endLatLng)
val expectedResult = (expectedDistance * 8 / 9).toInt()

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 repeats the same formula as calculateDistance, so if someone changes the ratio by mistake the test still passes. What about asserting against a known value instead? 0.001° of longitude at the equator is roughly 111 m, so we would expect around 98.

// Update camera position to trigger visibility LaunchedEffect
cameraState.position = CameraPosition.fromLatLngZoom(LatLng(37.7749, -122.4194), 14f)
composeTestRule.waitForIdle()
}

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 we assert something here? Right now the test passes as long as nothing crashes. Setting composeTestRule.mainClock.autoAdvance = false and advancing past visibilityDurationMillis would let us check that the bar shows after the camera change and hides again, which is the actual behaviour of this composable.

import com.google.common.truth.Truth.assertThat
import com.google.maps.android.compose.CameraPositionState
import com.google.maps.android.ktx.utils.sphericalDistance
import io.mockk.every

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: ScaleBar.kt uses com.google.maps.android.sphericalDistance. Should we use the same one here so the test and the production code stay on the same implementation?

Suggested change
import io.mockk.every
import com.google.maps.android.sphericalDistance

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