Skip to content

feat(robolectric): add MapsRobolectricTestRunner and deprecate @EnableMapsShadows - #12

Open
kikoso wants to merge 1 commit into
mainfrom
feat/maps-robolectric-test-runner
Open

kikoso wants to merge 1 commit into
mainfrom
feat/maps-robolectric-test-runner

Conversation

@kikoso

@kikoso kikoso commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

@EnableMapsShadows has never registered any shadows. It puts @Config(shadows = [...]) on an annotation class, and Robolectric does not read @Config through meta-annotations. Every test that used it got the Maps shadows from the robolectric.properties the library ships (found in #5). This adds a runner that registers the shadows on its own, so that file can be removed later.

MapsRobolectricTestRunner extends RobolectricTestRunner and passes it an injector that binds a GlobalConfigProvider with the 16 Maps shadows:

  • Only test classes that use the runner get the shadows. Any @Config on the class or method still merges on top (sdk, extra shadows, and so on).
  • All test classes using the runner share one injector, so Robolectric keeps reusing its sandboxes.
  • I first overrode buildGlobalConfig(), the obvious hook, and it does not work: Robolectric stores its result in a static field that only the first runner created in the JVM gets to set. With that version, 54 of 131 tests failed once the properties file was gone.

@EnableMapsShadows is now @Deprecated and points to the runner. It is not removed, since rc01 users may have it on their tests.

Migration in this repo: every test, sample, template and doc snippet that used @RunWith(RobolectricTestRunner::class) plus @EnableMapsShadows now uses @RunWith(MapsRobolectricTestRunner::class). The getMapBlocking() error messages point at the runner too. The #Lx-Ly region links in the skills were recomputed against the moved [START]/[END] tags. The module README has a new "Registering the Maps shadows" section, covering AndroidJUnit4 tests and the fact that an app with its own root robolectric.properties loses the shipped one.

robolectric.properties still ships. The plan is to remove it before 1.0.0.

Tests (MapsRobolectricTestRunnerTest):

  • the runner's config contains exactly MAPS_SHADOWS;
  • MAPS_SHADOWS lists every @Implements class in the shadows package, so it cannot drift the way the package-level properties file did (10 of 16);
  • a fixture with @Config(sdk = [33]) run through the runner gets both SDK 33 and ShadowMapView.

I mutation-checked the first two: dropping a shadow from the list, or binding Robolectric's default config instead, each fails its test.

Proof that the runner works without the file: in a scratch checkout of this branch, with all four robolectric.properties removed (the shipped ones and the module's test copy), ./gradlew test --rerun-tasks --no-build-cache runs 131 tests, 0 failing.

Ran ./gradlew test lint spotlessCheck apiCheck docs:dokkaGenerate --rerun-tasks --no-build-cache: green. The API change is additive (new class plus a MAPS_SHADOWS list).

Conflicts: #9 moves the :app tests edited here, and #7 touches some of the same skill files. Whichever merges later needs a rebase.

Replaces #5.

@snippet-bot

snippet-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

Here is the summary of possible violations 😱

Details

There are 10 possible violations for not having product prefix.

The end of the violation section. All the stuff below is FYI purposes only.


Here is the summary of changes.

You are about to add 24 region tags.
You are about to delete 23 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@github-actions

github-actions Bot commented Nov 6, 2026

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
golden-testing 90.42% new 58.00% new
robolectric-testing 84.25% new 51.87% new
visual-testing 36.54% new 25.07% new
TOTAL 79.07% new 44.10% new

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

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.

2 participants