Want to mock/stub out a Flutter platform channel/plugin? You can use setMockMethodCallHandler to register a mock handler for the underlying method channel:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
final List<MethodCall> log = <MethodCall>[]; MethodChannel channel = const MethodChannel('plugins.flutter.io/url_launcher'); // Register the mock handler. channel.setMockMethodCallHandler((MethodCall methodCall) async { log.add(methodCall); }); await launch("http://example.com/"); expect(log, equals(<MethodCall>[new MethodCall('launch', "http://example.com/")])); // Unregister the mock handler. channel.setMockMethodCallHandler(null); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.