您可以使用setMockMethodCallHandler为基础方法通道注册模拟处理程序:
https://docs.flutter.io/flutter/services/MethodChannel/setMockMethodCallHandler.html
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);


