相关疑难解决方法(0)

Flutter:测试共享首选项

我正在尝试测试此功能:

 void store(String x, String y) async {
    Map<String, dynamic> map = {
      'x': x,
      'y': y,
    };
    var jsonString = json.encode(map);
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString('fileName', jsonString);
  }
Run Code Online (Sandbox Code Playgroud)

我看到我可以用

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;
  });
Run Code Online (Sandbox Code Playgroud)

但是我不知道如何使用,特别是在我的情况下。

testing unit-testing dart flutter

5
推荐指数
2
解决办法
863
查看次数

标签 统计

dart ×1

flutter ×1

testing ×1

unit-testing ×1