-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[android_alarm_manager] Testing and documentation #2283
Conversation
|
I don't like exposing the internal state with |
cyanglaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| /// them out in the test environment. This is only visible for the unit tests and | ||
| /// should not be accessed directly by users of the plugin. | ||
| @visibleForTesting | ||
| class InstanceWrappers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this appear in the docs for the plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Technically this was a "missing doc" before since this API is public and visible to users of the plugin. I figured a warning saying not to touch this made the most sense as the only user-facing documentation on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not a fan of polluting the API surface with code only used for testing. If this wasn't going to appear in the docs that would be a different story, but it would be great if we could hide this somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, I'm going to delete this anyway as @cyanglaz suggested in #2283 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, Github hadn't loaded the earlier comment at the time I posted my last one.
Ideally I'd like to avoid all @visibleForTesting identifiers too but I'm not sure how to completely do it here. DateTime.now and PluginUtilities.getCallbackHandle are both static and referenced statically internally. AndroidAlarmManager itself is static so I can't use constructor injection. The unit tests can only touch the class through its public API surfaces. Right now I am cutting down on the visibility a little bit from what's currently in this patch, but I'm still adding this method to AndroidAlarmManager itself:
/// This is exposed for the unit tests. It should not be accessed by users of
/// the plugin.
@visibleForTesting
static void setTestOverides({Now now, GetCallbackHandle getCallbackHandle}) {
_now = (now ?? _now);
_getCallbackHandle = (getCallbackHandle ?? _getCallbackHandle);
}And then the class internally is using _now and _getCallbackHandle instead of the static functions.
If you have any ideas on how to avoid it totally I would be happy to hear it, I'd love to avoid this too. I'm also exposing the MethodChannel so I can test it too.
Edit: Strike the bit about the MethodChannel above, sorry. It looks like I don't actually need to access it directly if I just construct an identical instance in the tests and act on that.
packages/android_alarm_manager/test/android_alarm_manager_test.dart
Outdated
Show resolved
Hide resolved
packages/android_alarm_manager/test/android_alarm_manager_test.dart
Outdated
Show resolved
Hide resolved
packages/android_alarm_manager/test/android_alarm_manager_test.dart
Outdated
Show resolved
Hide resolved
packages/android_alarm_manager/test/android_alarm_manager_test.dart
Outdated
Show resolved
Hide resolved
Unit tests the plugin, and adds a lint for missing DartDocs.
- Wrap InstanceWrappers into a single `setTestOverride` method. - Replace potentially garbage collected lambdas with top level functions.
* [android_alarm_manager] Testing and documentation Unit tests the plugin, and adds a lint for missing DartDocs. * Review feedback - Wrap InstanceWrappers into a single `setTestOverride` method. - Replace potentially garbage collected lambdas with top level functions. * Review feedback
Related Issues
Fixes flutter/flutter#44385.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?