jonataslaw / get_storage

A fast, extra light and synchronous key-value storage to Get framework
MIT License
369 stars 83 forks source link

Is it possible to retrieve data from Get_Storage in Integration Tests? #76

Open d-apps opened 3 years ago

jonataslaw commented 3 years ago

Yeah, but you need mock the storage driver

Ch4rl3B commented 3 years ago

Hi @jonataslaw, I'm having this problem when I run functional test on a Gitlab pipeline. The thing is that locally on my computer all test passed successfully but in the Gitlab CI/CD i get this error:

Running "flutter pub get" in xxxxxx-mobile...                       4.9s
00:21 +13 -1: /builds/aaaaa-eeeeeeeeeee/xxxxxx/xxxxxx-mobile/test/functional/home_page_test.dart: Test Home Page is the first shown widget, and correctly navigates to CollectionFilterPage when pressing the YYY Collection button [E]
  ProcessException: Failed to find "xdg-user-dir" in the search path.
    Command: xdg-user-dir 
  package:get_storage/src/storage_impl.dart 47:7  GetStorage._init

in my test i have this code:

void main() async {
  TestWidgetsFlutterBinding.ensureInitialized();
  late GetStorage g;

  const channel = MethodChannel('plugins.flutter.io/path_provider');
  void setUpMockChannels(MethodChannel channel) {
    channel.setMockMethodCallHandler((MethodCall methodCall) async {
      if (methodCall.method == 'getApplicationDocumentsDirectory') {
        return '.';
      }
    });
  }

  setUpAll(() async {
    setUpMockChannels(channel);
  });

  setUp(() async {
    await GetStorage.init();
    g = GetStorage();
    await g.erase();
  });

  // The test goes here...

But this doesn't work.

sebastianbuechler commented 2 years ago

Yeah, but you need mock the storage driver

@jonataslaw Do you have an example? @d-apps How did you solve this issue?

EmadBeltaje commented 1 year ago

@jonataslaw is there any example yet? @d-apps have you find solution?

SeongUgJung commented 1 year ago

I left same comment : https://github.com/jonataslaw/get_storage/issues/109#issuecomment-1397892672

I got this hint from path_provider and it seems that worked as well in mac-os (my local machine), ubuntu (CI machine) https://github.com/flutter/plugins/blob/main/packages/path_provider/path_provider_foundation/test/messages_test.g.dart#L24 ``` void main() { void setUpMockChannels() { const MessageCodec codec = StandardMessageCodec(); const BasicMessageChannel channel = BasicMessageChannel('dev.flutter.pigeon.PathProviderApi.getDirectoryPath', codec); channel.setMockMessageHandler((Object? message) async { const String output = '.'; return [output]; }); } setUpAll(() { setUpMockChannels(); }); } ```
ghost commented 8 months ago

for anyone interested how to get it working now see this, in short you need to mock PathProviderPlatform