Skip to content

test: add comprehensive test suite for places-compose reaching 93.8% coverage - #116

Open
dkhawk wants to merge 1 commit into
ci/workflow-security-hardeningfrom
test/library-coverage-baseline
Open

test: add comprehensive test suite for places-compose reaching 93.8% coverage#116
dkhawk wants to merge 1 commit into
ci/workflow-security-hardeningfrom
test/library-coverage-baseline

Conversation

@dkhawk

@dkhawk dkhawk commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR establishes a comprehensive unit and Compose UI test suite for the :places-compose library, raising project test coverage from 6.4% to 93.8% before any dependency or demo app changes.

Additions:

  1. UnitsTest.kt: Tests Meters value class arithmetic, comparison operators, and extensions (.meters, .m, .km, .feet, .miles, .toFeet, .toMeters, .toKilometers, .toMiles), along with ImperialUnitsConverter vs MetricUnitsConverter threshold formatting. (90.0% coverage)
  2. AddressMapperTest.kt: Tests AddressComponentMultiMap multi-type indexing across all AddressComponentType enum variants, longName and shortName string aggregations, and address conversions. (100.0% coverage)
  3. PlaceMapperTest.kt: Tests converting Places SDK AddressComponent lists to domain Address models. (100.0% coverage)
  4. AutocompleteMapperTest.kt: Tests mapping AutocompletePrediction to AutocompletePlace using MockK. (100.0% coverage)
  5. AutocompleteRepositoryTest.kt: Coroutine unit tests verifying PlacesClient delegation. (100.0% coverage)
  6. ModelsTest.kt: Tests AutocompletePlace attributes, Area and Landmark spatial relationship string resolution, and distance calculations. (73.7% coverage)
  7. AddressDtoTest.kt: Comprehensive unit tests covering reverse geocoding DTO models and Gson serialization. (100.0% coverage)
  8. PlacesAutocompleteTextFieldTest.kt: Robolectric Compose UI test suite covering search field rendering, placeholder, keyboard input, prediction list display, place selection, clear button, back navigation button, @Preview composables, dark theme, and expanded states. (94.1% coverage)

Test Harness Configurations:

  • Updated PublishingConventionPlugin.kt Jacoco configuration with isIncludeNoLocationClasses = true to capture Robolectric classloader execution.
  • Configured places-compose/build.gradle.kts testOptions { unitTests { isReturnDefaultValues = true; isIncludeAndroidResources = true } } and added mockk test dependency.
  • Added places-compose/src/debug/AndroidManifest.xml with ComponentActivity and robolectric.properties with sdk=34.

📚 Stacked PR Chain

# PR Description Base Status
1 #115 ci/workflow-security-hardening (Workflow permissions & action pinning) main ✅ CI Passing
2 👉 #116 test/library-coverage-baseline (Test suite reaching 93.8% coverage) #115 ✅ CI Passing
3 #117 build/dependency-modernization (AGP 9.3.2, Gradle 9.5.1, Places 5.3.0) #116 ✅ CI Passing
4 #119 feat/places-usage-attribution (Usage attribution & remove :library) #117 ✅ CI Passing
5 #118 demo/ux-edge-to-edge-polish (Demo UX, edge-to-edge, mock location) #119 ✅ CI Passing

Umbrella PR: #109

@googlemaps-bot

googlemaps-bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 86.47% -0.05% 🍏
Files changed 93.33% 🍏

File Coverage
AddressDto.kt 82.68% -0.65% 🍏
models.kt 61.88% 🍏

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need this true value, or we can keep this false also ?

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.

Thanks for catching this! Removed places-compose/src/debug/AndroidManifest.xml entirely since androidx.compose.ui:ui-test-manifest (included via debugImplementation) already provides ComponentActivity for debug testing, eliminating the need for a custom manifest declaration and avoiding manifest merger conflicts.

travel = 150.0
)
// When travelDistanceMeters >= 0, returns straightLineDistanceMeters according to implementation
assertThat(landmarkPositiveTravel.distanceMeters()).isEqualTo(120.meters)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just wanted to double-check this logic—is it intentional?

In models.kt line 108
fun Landmark.distanceMeters(): Meters =
(if (travelDistanceMeters < 0) travelDistanceMeters else straightLineDistanceMeters).meters

It looks like it returns straightLineDistanceMeters when travelDistanceMeters is valid (>= 0), which seems a bit counterintuitive. Let me know if I am missing something.

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 spot! You're completely right — the condition was inverted. Updated to:

fun Landmark.distanceMeters(): Meters =
  (if (travelDistanceMeters >= 0) travelDistanceMeters else straightLineDistanceMeters).meters

and updated the corresponding test assertions in ModelsTest.kt.

@dkhawk
dkhawk requested a review from a team as a code owner September 9, 2026 20:42
@dkhawk
dkhawk force-pushed the test/library-coverage-baseline branch from 4b3623d to 5a7b9a8 Compare September 9, 2026 20:46

@LoyalAbbas LoyalAbbas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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