Flutter Test MissingPluginException

后端 未结 3 1728
刺人心
刺人心 2020-12-03 17:28

Running tests which rely on the SharedPreferences Plugin always result in

MissingPluginException(No implementation found for method getAll on channel plugins         


        
3条回答
  •  Happy的楠姐
    2020-12-03 17:36

    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 {}; // set initial values here if desired
        }
        return null;
      });
    

提交回复
热议问题