From d15a36124429703a0457e169122402ac07f9388b Mon Sep 17 00:00:00 2001 From: TruongSinh Tran-Nguyen Date: Wed, 13 Feb 2019 01:37:00 +0700 Subject: [PATCH] `flutter create --template=plugin` now include flutter unit test (#26456) --- .../templates/plugin/pubspec.yaml.tmpl | 4 ++++ .../plugin/test/projectName_test.dart.tmpl | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 packages/flutter_tools/templates/plugin/test/projectName_test.dart.tmpl diff --git a/packages/flutter_tools/templates/plugin/pubspec.yaml.tmpl b/packages/flutter_tools/templates/plugin/pubspec.yaml.tmpl index a4f1e85fb5..2476e4f27d 100644 --- a/packages/flutter_tools/templates/plugin/pubspec.yaml.tmpl +++ b/packages/flutter_tools/templates/plugin/pubspec.yaml.tmpl @@ -11,6 +11,10 @@ dependencies: flutter: sdk: flutter +dev_dependencies: + flutter_test: + sdk: flutter + # For information on the generic Dart part of this file, see the # following page: https://www.dartlang.org/tools/pub/pubspec diff --git a/packages/flutter_tools/templates/plugin/test/projectName_test.dart.tmpl b/packages/flutter_tools/templates/plugin/test/projectName_test.dart.tmpl new file mode 100644 index 0000000000..cfcb38436d --- /dev/null +++ b/packages/flutter_tools/templates/plugin/test/projectName_test.dart.tmpl @@ -0,0 +1,21 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:{{projectName}}/{{projectName}}.dart'; + +void main() { + const MethodChannel channel = MethodChannel('{{projectName}}'); + + setUp(() { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + return '42'; + }); + }); + + tearDown(() { + channel.setMockMethodCallHandler(null); + }); + + test('getPlatformVersion', () async { + expect(await {{pluginDartClass}}.platformVersion, '42'); + }); +}