最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Flutter running unit test on Mac cannot find getApplicationDocumentsDirectory implementation - Stack Overflow

programmeradmin1浏览0评论

I'm facing this issue when running some flutter unit test that calls some code that uses getApplicationDocumentsDirectory():

package:flutter/src/services/platform_channel.dart 368:7  MethodChannel._invokeMethod

MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)

This was running a few weeks ago, so it seemengly got broken after some flutter/deps upgrade.

These are the deps in my pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  flame: ^1.22.0
  flame_audio: ^2.10.3
  flame_fe2d: ^0.18.2
  shared_preferences: ^2.0.13
  package_info_plus: ^8.1.0
  sprintf: ^6.0.0
  archive: ^3.3.4
  path_provider: ^2.0.15
  sqflite: ^2.4.0
  cupertino_icons: ^1.0.8
  crypto: ^3.0.6
  path: ^1.9.0
  intl: ^0.20.1
  logging: ^1.3.0

And this is my flutter doctor output:

 % flutter doctor                   
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.3.1 24D70 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0-rc4)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

I have seen several other questions related to this in StackOverflow but none specifically addressing the case of unit tests running on Mac, and none of the advice on these others helped me to fix this specific issue.

I'm facing this issue when running some flutter unit test that calls some code that uses getApplicationDocumentsDirectory():

package:flutter/src/services/platform_channel.dart 368:7  MethodChannel._invokeMethod

MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)

This was running a few weeks ago, so it seemengly got broken after some flutter/deps upgrade.

These are the deps in my pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  flame: ^1.22.0
  flame_audio: ^2.10.3
  flame_fe2d: ^0.18.2
  shared_preferences: ^2.0.13
  package_info_plus: ^8.1.0
  sprintf: ^6.0.0
  archive: ^3.3.4
  path_provider: ^2.0.15
  sqflite: ^2.4.0
  cupertino_icons: ^1.0.8
  crypto: ^3.0.6
  path: ^1.9.0
  intl: ^0.20.1
  logging: ^1.3.0

And this is my flutter doctor output:

 % flutter doctor                   
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.3.1 24D70 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0-rc4)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

I have seen several other questions related to this in StackOverflow but none specifically addressing the case of unit tests running on Mac, and none of the advice on these others helped me to fix this specific issue.

Share asked Mar 3 at 10:40 Fran MarzoaFran Marzoa 4,5461 gold badge41 silver badges60 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

There's no getApplicationDocumentsDirectory implementation on the test environment. So you should set a mock handler using setMockMethodCallHandler.
This answer might be helpful.

发布评论

评论列表(0)

  1. 暂无评论