颤振测试MissingPluginException [英] Flutter Test MissingPluginException
本文介绍了颤振测试MissingPluginException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
依赖SharedPreferences插件的运行测试始终会导致
Running tests which rely on the SharedPreferences Plugin always result in
MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
我的pubspec.yaml
My pubspec.yaml
dev_dependencies:
flutter_test:
sdk: flutter
dependencies:
flutter:
sdk: flutter
shared_preferences: 0.2.3
该代码在应用程序本身中正常工作。
我是否缺少我需要做的某些事情才能运行使用插件的测试?
The code for works fine in the application itself. Am i missing something i need to do in order to run tests which make use of a plugin?
推荐答案
如果您使用的是shared_preferences 0.2.4及更高版本,请使用 setMockInitialValues
:
If you're using shared_preferences 0.2.4 and above, use setMockInitialValues
:
SharedPreferences.setMockInitialValues({}); // set initial values here if desired
对于较早的版本,您可以手动进行操作:
For earlier versions you can do it manually:
const MethodChannel('plugins.flutter.io/shared_preferences')
.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == 'getAll') {
return <String, dynamic>{}; // set initial values here if desired
}
return null;
});
这篇关于颤振测试MissingPluginException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文