Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

Eliminates usage of OCMock in the native iOS unit tests:

  • Creates a protocol for image asset loading that wraps that part of the registrar and the UIImage class method to replace mocking with injecting a protocol implementation.
  • Creates an abstract delegate for event reporting, instead of all of the sub-controllers communicating directly with the FlutterAPI instance.
  • Creates an abstract delegate for tile queries, instead of all of the tile controller communicating directly with the FlutterAPI instance.
  • Replaces mocking of our test subclass of the Google Maps view object with slightly more logic on that existing test subclass.
  • Replaces mocking of our existing protocols with simple manual fakes that lets us test the same assertions.
  • Eliminates static mock testing of GMSCameraUpdate.

Unblocks flutter/flutter#119108

Pre-Review Checklist

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the iOS native unit tests for google_maps_flutter by eliminating the use of OCMock. It introduces new protocols (FGMAssetProvider, FGMMapEventDelegate, FGMTileProviderDelegate) and their concrete implementations to allow for dependency injection, thereby improving testability. The changes include updating controller initializers to use these new delegates/providers and replacing OCMock-based test setups with custom fakes and direct assertions. The CHANGELOG.md and pubspec.yaml have been updated to reflect these changes. The refactoring is comprehensive and aligns well with the stated objective of improving testability.

// GMSCameraUpdate is not inspectable, so this test just ensures that the codepath
// doesn't throw. FGMGetCameraUpdateForPigeonCameraUpdate is simple enough that
// injecting a wrapper would not meaningfully improve test coverage, since the non-test
// implementation would be about as complex as the conversion function itself.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This set of changes is the only place where this PR actually removes test coverage. The only way to test this without the static class mock (the worst kind of OCMock mocking, so I would want to eliminate this even without OCMock being problematic for Swift migration) would be to make a factory protocol that wraps all of the static factor methods on GMSCameraUpdate.

I did seriously consider that, but the implementation being tested is almost as simple as the wrapper class we would need to write—by intentional design of FGMPlatformCameraUpdate being a direct parallel of GMSCameraUpdate. That wrapper class wouldn't be testable, so it felt like it would be improving test coverage on paper without meaningfully adding any real coverage.

If anyone feels strongly the other way, I can add the wrapper.

@stuartmorgan-g
Copy link
Collaborator Author

(Ideally I would have done this before #10852 rather than after, but I didn't think about that until it was too late. Once #10852 it'll be easy to sync this change across all the copies before landing this.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant