test: skip map instrumentation tests when no Maps API key is available - #1016
Merged
Merged
Conversation
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.
Coverage (unit tests)No unit baseline recorded in
Line and branch coverage from unit test reports. History is recorded in |
Contributor
Code Coverage
|
kikoso
marked this pull request as ready for review
September 28, 2026 13:47
dkhawk
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
run-instrumentation-testfails 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 readsecrets.ACTIONS_API_KEY, so the "Inject Maps API Key" step takes its fallback branch and writesMAPS_API_KEY=YOUR_API_KEY.hasValidApiKeyis then false and every map-dependent test hits:which throws
IllegalStateExceptionand 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 withComposeTimeoutException. 19 of the last 21 instrumentation runs ondependabot/*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
checkwith a JUnit assumption behind a shared helper inTestUtils.kt, and adds the missing guard toStreetViewTests.Nothing changes when a key is present.
Two things reviewers should know
Three tests were passing for the wrong reason.
testMarkerStateCannotBeReusedand its two siblings declare@Test(expected = IllegalStateException::class). Without a key they were satisfied by the missing-keyIllegalStateExceptionitself, 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>withskipped="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:
MAPS_API_KEY=YOUR_API_KEYBUILD SUCCESSFUL, all 33 non-passing results recorded asAssumptionViolatedExceptionThe two failures with a real key,
GoogleMapViewTests.testStartingCameraPositionandMapInColumnTests.testScrollColumn_MapCameraRemainsSame, fail identically onmainon the same emulator. They are pre-existing and out of scope here../gradlew lintand:maps-app:testDebugUnitTestboth 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.