You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(robolectric): stop shipping robolectric.properties in the library - #5
robolectric-testing packages a top-level robolectric.properties that lists all 16 Maps shadows. Once a consumer adds the dependency, Robolectric picks that file up from the classpath and registers the Maps shadows for every Robolectric test in the project, including tests that never touch Maps. If the consumer has their own robolectric.properties (for sdk, application, and so on), only one of the two files wins, depending on classpath order.
This removes all three copies from the library sources:
src/main/resources/robolectric.properties: the one that ships in the AAR and causes the problem.
src/main/resources/com/google/maps/android/robolectric/shadows/robolectric.properties: a package-level copy that had drifted and only listed 10 of the 16 shadows.
src/main/java/.../shadows/robolectric.properties: never packaged, since Gradle does not copy resources from src/main/java.
@EnableMapsShadows stays the supported way to turn on the shadows, and every test in this repo already uses it (or an explicit @Config(shadows = ...)). The module's own test resources keep their robolectric.properties.
Behavior change for rc01 users: anyone relying on the shadows being picked up automatically needs to add @EnableMapsShadows to their test classes. I updated the module README, which advertised the automatic discovery.
RobolectricConfigLeakTest in golden-testing guards this. That module consumes robolectric-testing the same way an app does, so its test classpath shows what consumers get. Both tests fail on main and pass with this change.
Ran ./gradlew test lint spotlessCheck apiCheck docs:dokkaGenerate: all green.
Correction: this PR is not green. My local run was served from the Gradle build cache. With --rerun-tasks, 16 of 21 :app unit tests fail with GooglePlayServicesMissingManifestValueException, same as CI.
The cause is that @EnableMapsShadows never registers anything. It puts @Config(shadows = [...]) on an annotation class, and Robolectric does not read @Config through meta-annotations. The tests only passed because the shipped robolectric.properties registered the shadows globally.
So the annotation has to work before this file can go. Holding this PR until we decide how.
Closing this for now. The file is the only thing that registers the Maps shadows today, for us and for anyone on rc01, so removing it first breaks every consumer.
Plan instead:
Add a MapsRobolectricTestRunner that registers the shadows through buildGlobalConfig(), and deprecate @EnableMapsShadows in favor of it (it can't be fixed, since Robolectric doesn't read @Config through annotations).
Keep shipping robolectric.properties through the RCs, and document that an app with its own root robolectric.properties can lose it.
Remove the file before 1.0.0 stable, reusing the leak test from this PR.
Runner PR: #12. With it, all 131 tests pass with every robolectric.properties removed. The buildGlobalConfig() override I proposed above does not work (static, first runner wins), so it binds a GlobalConfigProvider through the injector instead.
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
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.
robolectric-testingpackages a top-levelrobolectric.propertiesthat lists all 16 Maps shadows. Once a consumer adds the dependency, Robolectric picks that file up from the classpath and registers the Maps shadows for every Robolectric test in the project, including tests that never touch Maps. If the consumer has their ownrobolectric.properties(forsdk,application, and so on), only one of the two files wins, depending on classpath order.This removes all three copies from the library sources:
src/main/resources/robolectric.properties: the one that ships in the AAR and causes the problem.src/main/resources/com/google/maps/android/robolectric/shadows/robolectric.properties: a package-level copy that had drifted and only listed 10 of the 16 shadows.src/main/java/.../shadows/robolectric.properties: never packaged, since Gradle does not copy resources fromsrc/main/java.@EnableMapsShadowsstays the supported way to turn on the shadows, and every test in this repo already uses it (or an explicit@Config(shadows = ...)). The module's own test resources keep theirrobolectric.properties.Behavior change for rc01 users: anyone relying on the shadows being picked up automatically needs to add
@EnableMapsShadowsto their test classes. I updated the module README, which advertised the automatic discovery.RobolectricConfigLeakTestingolden-testingguards this. That module consumesrobolectric-testingthe same way an app does, so its test classpath shows what consumers get. Both tests fail onmainand pass with this change.Ran
./gradlew test lint spotlessCheck apiCheck docs:dokkaGenerate: all green.