diff --git a/dev/devicelab/bin/tasks/plugin_dependencies_test.dart b/dev/devicelab/bin/tasks/plugin_dependencies_test.dart index fa2bd9e90dc2..f6d2e1895ccc 100644 --- a/dev/devicelab/bin/tasks/plugin_dependencies_test.dart +++ b/dev/devicelab/bin/tasks/plugin_dependencies_test.dart @@ -215,6 +215,10 @@ public class DummyPluginAClass { final List dependencyGraph = jsonContent['dependencyGraph'] as List; const String kExpectedPluginsDependenciesContent = '[' + '{' + '"name":"integration_test",' + '"dependencies":[]' + '},' '{' '"name":"plugin_a",' '"dependencies":["plugin_b","plugin_c","plugin_d"]' diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 7424624e5179..cbccb1fb9e65 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -595,7 +595,7 @@ Your $application code is in $relativeAppMain. templateContext['androidPluginIdentifier'] = androidPluginIdentifier; generatedCount += await generateApp( - ['app', 'app_test_widget'], + ['app', 'app_test_widget', 'app_integration_test'], project.example.directory, templateContext, overwrite: overwrite, diff --git a/packages/flutter_tools/templates/app/pubspec.yaml.tmpl b/packages/flutter_tools/templates/app/pubspec.yaml.tmpl index f615a78b941b..8e9a7d66fb0d 100644 --- a/packages/flutter_tools/templates/app/pubspec.yaml.tmpl +++ b/packages/flutter_tools/templates/app/pubspec.yaml.tmpl @@ -68,6 +68,10 @@ dependencies: cupertino_icons: ^1.0.2 dev_dependencies: +{{#withPlatformChannelPluginHook}} + integration_test: + sdk: flutter +{{/withPlatformChannelPluginHook}} flutter_test: sdk: flutter diff --git a/packages/flutter_tools/templates/app_integration_test/integration_test/plugin_integration_test.dart.tmpl b/packages/flutter_tools/templates/app_integration_test/integration_test/plugin_integration_test.dart.tmpl new file mode 100644 index 000000000000..4eb49eceb0d7 --- /dev/null +++ b/packages/flutter_tools/templates/app_integration_test/integration_test/plugin_integration_test.dart.tmpl @@ -0,0 +1,31 @@ +// This is a basic Flutter integration test. +{{#withPlatformChannelPluginHook}} +// +// Since integration tests run in a full Flutter application, they can interact +// with the host side of a plugin implementation, unlike Dart unit tests. +{{/withPlatformChannelPluginHook}} +// +// For more information about Flutter integration tests, please see +// https://docs.flutter.dev/cookbook/testing/integration/introduction + + +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +{{#withPlatformChannelPluginHook}} +import 'package:{{pluginProjectName}}/{{pluginProjectName}}.dart'; +{{/withPlatformChannelPluginHook}} + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); +{{#withPlatformChannelPluginHook}} + + testWidgets('getPlatformVersion test', (WidgetTester tester) async { + final {{pluginDartClass}} plugin = {{pluginDartClass}}(); + final String? version = await plugin.getPlatformVersion(); + // The version string depends on the host platform running the test, so + // just assert that some non-empty string is returned. + expect(version?.isNotEmpty, true); + }); +{{/withPlatformChannelPluginHook}} +} diff --git a/packages/flutter_tools/templates/template_manifest.json b/packages/flutter_tools/templates/template_manifest.json index c452abec1b01..b2a03b6aba16 100644 --- a/packages/flutter_tools/templates/template_manifest.json +++ b/packages/flutter_tools/templates/template_manifest.json @@ -141,6 +141,8 @@ "templates/app_test_widget/test/widget_test.dart.tmpl", + "templates/app_integration_test/integration_test/plugin_integration_test.dart.tmpl", + "templates/cocoapods/Podfile-ios-objc", "templates/cocoapods/Podfile-ios-swift", "templates/cocoapods/Podfile-macos", diff --git a/packages/flutter_tools/test/commands.shard/hermetic/create_usage_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/create_usage_test.dart index 86ebe770eaee..9c419c3567f4 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/create_usage_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/create_usage_test.dart @@ -75,6 +75,7 @@ void main() { } final List templatePaths = [ globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'app'), + globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'app_integration_test'), globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'app_shared'), globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'app_test_widget'), globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'cocoapods'), diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart index 0d3674421b5b..a264ad8459ac 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -633,6 +633,27 @@ void main() { ), }); + testUsingContext('plugin example app includes an integration test', () async { + await _createAndAnalyzeProject( + projectDir, + ['--template=plugin'], + [ + 'example/integration_test/plugin_integration_test.dart', + ], + ); + return _runFlutterTest(projectDir.childDirectory('example')); + }, overrides: { + Pub: () => Pub.test( + fileSystem: globals.fs, + logger: globals.logger, + processManager: globals.processManager, + usage: globals.flutterUsage, + botDetector: globals.botDetector, + platform: globals.platform, + stdio: mockStdio, + ), + }); + testUsingContext('kotlin/swift plugin project', () async { return _createProject( projectDir, diff --git a/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart b/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart index af21d227cc39..5ea05390d1d9 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart @@ -285,7 +285,8 @@ void main() { final PackagesCommand command = await runCommandIn(exampleProjectPath, 'get'); final PackagesGetCommand getCommand = command.subcommands['get']! as PackagesGetCommand; - expect((await getCommand.usageValues).commandPackagesNumberPlugins, 1); + // A plugin example depends on the plugin itself, and integration_test. + expect((await getCommand.usageValues).commandPackagesNumberPlugins, 2); }, overrides: { Stdio: () => mockStdio, Pub: () => Pub.test(