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
receiveBroadcastStream is used in dart side to listen event post from android / iOS native side.
It works fine when running on device.
When I write unit test case, I noticed setMockMethodCallHandler can be used to mock method response from native side. But I can't find any way to mock event post ?
In Shortly,
I post event to dart size from android / iOS native side using EventChannel.EventSinkFlutterEventSink . How to mock this in unit test ?
Thanks.
flutter doctor summary
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Mac OS X 10.14.3 18D109, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.4)
[✓] Android Studio (version 3.5)
[✓] IntelliJ IDEA Ultimate Edition (version 2019.1.2)
[✓] VS Code (version 1.37.1)
[✓] Connected device (1 available)
Not a great solution, but still a solution. here
EventChannel is backed using a MethodChannel... so do not worry about the link above creating a MethodChannel.
Flutter could have something similar to MethodChannel. setMockMethodCallHandler.
The event Stream comes from MessageHandler set in receiveBroadcastStream.
I tried to send message by call defaultBinaryMessenger.send which is wrong.
Actually, defaultBinaryMessenger.handlePlatformMessage is right.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
[-]How to mock EventChannel ?[/-][+]How to mock EventChannel in unit test?[/+]juliocbcotta commentedon Aug 21, 2019
Not a great solution, but still a solution. here
EventChannel is backed using a MethodChannel... so do not worry about the link above creating a MethodChannel.
Flutter could have something similar to
MethodChannel. setMockMethodCallHandler.befovy commentedon Aug 21, 2019
@BugsBunnyBR 👍 Your answer has resolved my problems. Thanks.
I known EventChannel is backed using a MethodChannel.
The event Stream comes from
MessageHandlerset inreceiveBroadcastStream.I tried to send message by call
defaultBinaryMessenger.sendwhich is wrong.Actually,
defaultBinaryMessenger.handlePlatformMessageis right.github-actions commentedon Aug 28, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.