jonataslaw / get_storage

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

GetStorage + Mockito GetStorage.getValues features a non-nullable unknown return type #80

Open babakoto opened 3 years ago

babakoto commented 3 years ago

I can't mock GetStorage

get_storage: ^2.0.3

@GenerateMocks([GetStorage])
void main() {

  test('', () {

  });
}

Invalid @GenerateMocks annotation: Mockito cannot generate a valid mock class which implements 'GetStorage' for the following reasons: The method 'GetStorage.getKeys' features a non-nullable unknown return type, and cannot be stubbed without a dummy generator specified on the MockSpec. The method 'GetStorage.getValues' features a non-nullable unknown return type, and cannot be stubbed without a dummy generator specified on the MockSpec. [INFO] Running build completed, took 22.9s

[✓] Flutter (Channel stable, 2.5.1, on Ubuntu 20.04.3 LTS 5.11.0-34-generic, locale fr_FR.UTF-8) [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3) ✗ cmdline-tools component is missing Run path/to/sdkmanager --install "cmdline-tools;latest" See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/linux#android-setup for more details. [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2020.3) [✓] Android Studio (version 4.2) [✓] VS Code [✓] Connected device (3 available)

leolopez89 commented 1 year ago

The solution is to use unsupportedMembers

@GenerateMocks(<Type>[], customMocks: <MockSpec<dynamic>>[
  MockSpec<GetStorage>(
      as: #MockGetStorage, unsupportedMembers: {#getKeys, #getValues}),
])