-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: making mocking simple #336
Comments
Providing a mechanism at |
@jpnurmi - you have more experience with this, WDYT? |
I'm all for making it easier to test D-Bus-based Dart and Flutter apps and packages. 👍 Funny, we just discussed the other day about having to "pollute" code for mocking. 😄 Mocking out P.S. @daadu, for that specific case, one could simply replace the void main() {
testWidgets('test with wifi', (tester) async {
ConnectivityPlatform.instance =
FakeConnectivityPlatform(ConnectivityResult.wifi);
await tester.pumpWidget(...);
await tester.pumpAndSettle();
expect(foo, somethingThatExpectsWifi);
});
}
class FakeConnectivityPlatform extends ConnectivityPlatform {
FakeConnectivityPlatform(this._result);
final ConnectivityResult _result;
@override
Future<ConnectivityResult> checkConnectivity() => Future.value(_result);
@override
Stream<ConnectivityResult> get onConnectivityChanged => const Stream.empty();
} |
Almost forgot about this solution (setting mocking actual messages/channels ( |
Something similar to how it is done in flutter with -
TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger.setMockMethodCallHandler(_methodChannel, _methodHandler);
Say for example, consider following dependecny graph
my_app
->connectivity_plus
->connectivity_plus_linux
->dbus
- know as a app developer - I would want to mock and test certain behaviour based on the result of where it is connected. It is possible to do this with other platform (like Android, iOS, mac which uses Flutter Platform Channels internally), but not with Linux as of now.PS: I recently published
mock_plugin
- to simplify mocking "plugin" library for the end-application developer to mock plugin behaviours - turns out most plugins supporting Linux, usesdbus.dart
- I would love to support that too withmock_plugin
if there is a way to mock DBus client/channel/messages.The text was updated successfully, but these errors were encountered: