Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Test MissingPluginException

Tags:

Running tests which rely on the SharedPreferences Plugin always result in

MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) 

My pubspec.yaml

dev_dependencies:   flutter_test:      sdk: flutter  dependencies:   flutter:      sdk: flutter   shared_preferences: 0.2.3 

The code for works fine in the application itself. Am i missing something i need to do in order to run tests which make use of a plugin?

like image 331
LoopLoop Avatar asked Jun 04 '17 17:06

LoopLoop


People also ask

How many types of testing are there in flutter?

There are three types of tests that Flutter supports. A unit test verifies the behavior of a method or class. A widget test verifies the behavior of Flutter widgets without running the app itself. An integration test (also called end-to-end testing or GUI testing) runs the full app.

What is integration testing in flutter?

Integration tests in Flutter are written using the integration test package, provided by the SDK. This is Flutter's version of Selenium WebDriver (generic web), Protractor (Angular), Espresso (Android), or Earl Gray (iOS). The package internally uses flutter driver to drive the test on a device.


1 Answers

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 <String, dynamic>{}; // set initial values here if desired     }     return null;   }); 
like image 76
Collin Jackson Avatar answered Sep 28 '22 02:09

Collin Jackson