问题描述
我正在开发本机插件并尝试进行单元测试。 所有单元测试都将在Dart中完成(无本机代码)。
Flutter有一个测试示例,说明如何使用setMockMethodCallHandler
测试从Dart到本机的调用方法通道。
问题是我还没有找到一种方法来测试从本地调用到使用setMethodCallHandler
处理来自本地的调用的Dart的方法通道。
这是一个例子
// main.dart
class Plugin {
static MethodChannel _channel = const MethodChannel('plugin');
Plugin() {
_channel.setMethodCallHandler((call) async {
print("called from native: ${call.method}");
});
}
}
// tests/main_test.dart
void main() {
const MethodChannel _channel = MethodChannel('core.super_router');
Plugin plugin;
setUp(() async {
TestWidgetsFlutterBinding.ensureInitialized();
plugin = Plugin();
});
test("call from native",() async {
_channel.invokeMethod("something");
// This call can't reach the handler in the Plugin
// And there is no method like mockInvokeMethod
});
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)