你的问题的简短答案似乎是否定的.Flutter 驱动程序(集成测试)只能与用户界面AFAIK交互.它无法拦截对插件的调用.它用于从UI测试整个应用程序.
然而,在单元和小部件测试中,可以拦截对插件的调用.这允许监视对插件的调用并模拟响应.这样你就可以测试插件的dart代码和/或使用插件的小部件.测试本机代码需要编写本机测试.
以下是截取对插件的调用进行测试的示例:
MethodChannel('audio_recorder')
.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
switch (methodCall.method) {
case 'start':
isRecording = true;
return null;
case 'stop':
isRecording = false;
return {
'duration': duration,
'path': path,
'audioOutputFormat': extension,
};
case 'isRecording':
return isRecording;
case 'hasPermissions':
return true;
default:
return null;
}
});
有关完整示例,请参见here