Skip to content

test: skip map instrumentation tests when no Maps API key is available - #1016

Merged
dkhawk merged 1 commit into
mainfrom
fix/skip-map-tests-without-api-key
Sep 28, 2026
Merged

dkhawk merged 1 commit into
mainfrom
fix/skip-map-tests-without-api-key

Conversation

@kikoso

@kikoso kikoso commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Problem

run-instrumentation-test fails on every Dependabot pull request, and on every fork PR, for a reason unrelated to the change under test. Dependabot-triggered and fork-triggered runs cannot read secrets.ACTIONS_API_KEY, so the "Inject Maps API Key" step takes its fallback branch and writes MAPS_API_KEY=YOUR_API_KEY. hasValidApiKey is then false and every map-dependent test hits:

check(hasValidApiKey) { "Maps API key not specified" }

which throws IllegalStateException and fails the build.

On #1015 that accounted for 29 of the 41 tests. The 30th failure, StreetViewTests, has no guard at all: it just waits for a panorama that can never load and dies with ComposeTimeoutException. 19 of the last 21 instrumentation runs on dependabot/* branches failed this way, including one whose only change was a GitHub Action version bump.

Change

A test that cannot run for lack of a credential is a skipped test, not a failing one. This replaces the check with a JUnit assumption behind a shared helper in TestUtils.kt, and adds the missing guard to StreetViewTests.

fun assumeValidApiKey() {
    assumeTrue("Maps API key not specified", hasValidApiKey)
}

Nothing changes when a key is present.

Two things reviewers should know

Three tests were passing for the wrong reason. testMarkerStateCannotBeReused and its two siblings declare @Test(expected = IllegalStateException::class). Without a key they were satisfied by the missing-key IllegalStateException itself, so they went green without ever reaching the marker-reuse logic they exist to test. JUnit 4.13.2 propagates assumption failures through the expected-exception check, so they now skip when there is no key and assert for real when there is.

The report still says "failures". AGP writes assumption failures into the connected-test XML as <failure> with skipped="0", so the generated HTML reads "33 failures / 19% successful" even though the task passes. The count is cosmetic, the build result is not. Worth knowing before someone opens the artifact on a green run and panics.

Verification

Run on a local API 30 emulator, since a same-repo branch like this one gets the real secret in CI and therefore will not exercise the no-key path:

Condition Result
MAPS_API_KEY=YOUR_API_KEY BUILD SUCCESSFUL, all 33 non-passing results recorded as AssumptionViolatedException
Real key 39 of 41 pass

The two failures with a real key, GoogleMapViewTests.testStartingCameraPosition and MapInColumnTests.testScrollColumn_MapCameraRemainsSame, fail identically on main on the same emulator. They are pre-existing and out of scope here.

./gradlew lint and :maps-app:testDebugUnitTest both pass.

Follow-up worth considering

This makes CI honest, but it does mean dependency bumps get a green check with the map tests skipped rather than real emulator coverage. If you want coverage back on those PRs, add an API-restricted copy of the key as a Dependabot secret (Settings > Secrets and variables > Dependabot). That layers on top of this change rather than replacing it, and it is the only option of the two that gives fork PRs nothing, so it is a judgement call about how much you trust a bot-authored branch with a key.

The emulator suite fails on every Dependabot pull request, and on forks,
for a reason that has nothing to do with the change under test: neither
can read the repository secret that supplies the Maps API key.

The workflow falls back to writing MAPS_API_KEY=YOUR_API_KEY, hasValidApiKey
is then false, and the map-dependent tests hit
check(hasValidApiKey) { "Maps API key not specified" }, which throws
IllegalStateException and fails the build. On PR #1015 that was 29 of 41
tests; the 30th, StreetViewTests, has no guard at all and instead timed out
waiting for a panorama that can never load.

A test that cannot run for lack of a credential is a skipped test, not a
failing one, so replace the check with a JUnit assumption via a shared
assumeValidApiKey() helper, and add the missing guard to StreetViewTests.

Two things worth knowing about the result:

- Three tests declare @test(expected = IllegalStateException::class) for
  marker-state reuse. Without a key they were being satisfied by the
  missing-key IllegalStateException itself, so they passed without ever
  exercising the reuse logic. JUnit 4.13.2 propagates assumption failures
  through the expected-exception check, so they now skip when no key is
  present and assert for real when one is.
- AGP writes assumption failures into the connected-test XML as <failure>
  with skipped="0", so the generated report still reads "33 failures" even
  though the task passes. The count is cosmetic; the build result is not.

Verified on an API 30 emulator: with MAPS_API_KEY=YOUR_API_KEY the task
succeeds with all 33 results recorded as AssumptionViolatedException, and
with a real key 39 of 41 tests pass. The two that fail,
GoogleMapViewTests.testStartingCameraPosition and
MapInColumnTests.testScrollColumn_MapCameraRemainsSame, fail identically on
main and are unrelated to this change.
@github-actions

Copy link
Copy Markdown

Coverage (unit tests)

No unit baseline recorded in coverage/history.csv yet, so this run only reports absolute numbers.

Module Line % Change Branch % Change
maps-compose 0.00% new 0.00% new
maps-compose-utils 2.04% new 0.49% new
maps-compose-widgets 0.00% new 0.00% new
TOTAL 0.42% new 0.09% new

Line and branch coverage from unit test reports. History is recorded in coverage/history.csv after each merge to main.

@googlemaps-bot

Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 24.61% ❌

There is no coverage information present for the Files changed

@kikoso
kikoso marked this pull request as ready for review September 28, 2026 13:47
@dkhawk
dkhawk merged commit 977ab46 into main Sep 28, 2026
13 checks passed
@dkhawk
dkhawk deleted the fix/skip-map-tests-without-api-key branch September 28, 2026 17:39
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