Repository navigation
test(widgets): add JVM unit and composable tests for ScaleBar - #1003
Conversation
Coverage (unit tests)Compared against
Line and branch coverage from unit test reports. History is recorded on the |
Code Coverage
|
9f260d3 to
bab4d05
Compare
34f2003 to
57c2723
Compare
57c2723 to
a63c557
Compare
bab4d05 to
d74586e
Compare
|
|
||
| val expectedDistance = startLatLng.sphericalDistance(endLatLng) | ||
| val expectedResult = (expectedDistance * 8 / 9).toInt() | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Addressed in 8b64c660 — replaced the repeated formula with known ground-truth assertions: a mocked Projection (0.001° longitude at the equator → 8/9 = 98 m) asserting isEqualTo(98), plus Mercator zoom 12 ground-truth checks at 0° (3350..3450 m) and 60° (1650..1750 m, verifying cos(60°) = 0.5).
| // Update camera position to trigger visibility LaunchedEffect | ||
| cameraState.position = CameraPosition.fromLatLngZoom(LatLng(37.7749, -122.4194), 14f) | ||
| composeTestRule.waitForIdle() | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Addressed in 8b64c660 — added assertIsDisplayed() checks for "0 ft" / "0 m" in testScaleBar_rendersWithoutCrashing, and updated testDisappearingScaleBar_showsOnCameraChangeAndHidesAfterDuration with mainClock.autoAdvance = false to verify the bar displays on initial composition, hides after visibilityDurationMillis, re-appears on camera position change, and hides again.
| 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 |
There was a problem hiding this comment.
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?
| import io.mockk.every | |
| import com.google.maps.android.sphericalDistance |
There was a problem hiding this comment.
Addressed in 8b64c660 — now that the test asserts known ground-truth values instead of recomputing the distance formula, the sphericalDistance import has been removed from ScaleBarTest.kt altogether.
d74586e to
95218a8
Compare
a63c557 to
1a8f666
Compare
95218a8 to
8cb7775
Compare
df2a0d9 to
ee29efc
Compare
253ef05 to
a837bf7
Compare
ee29efc to
5dcab93
Compare
5dcab93 to
6134e13
Compare
a837bf7 to
2551feb
Compare
- 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.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
Coverage (instrumentation tests)
|
* 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.
* 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.
…st to KTX helpers (#1001) * test: add JVM unit and composable integration tests using Android Maps Testing Toolkit * test(widgets): add JVM unit and composable tests for ScaleBar (#1003) * 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. * test(widgets): address PR #1001 review feedback - 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.
Description
Stacked PR on top of #1001 (
feature/robolectric-tests).Introduces JVM unit and Compose integration tests using Robolectric and the Android Maps Testing Toolkit (
com.google.maps.android:maps-testing-robolectric) formaps-compose-widgets, bringing module line coverage up from 0.00% to 67.12% (instruction coverage from 0.00% to 80.68%).Summary of Changes
robolectric,mockk,truth,androidx.test.compose.ui,maps.testing.robolectric) inmaps-compose-widgets/build.gradle.kts.ComponentActivityfor Robolectric Compose rule hosting.ScaleBarTest.ktcovering canvas distance calculation, unit conversions (ft, mi),ScaleBarcomposable rendering, andDisappearingScaleBarcamera position animation/state changes.cc @LoyalAbbas @kikoso