Commit f0c2d5ed authored by Phil Quitslund's avatar Phil Quitslund Committed by GitHub

Flutter create widget test template. (#11304)

* Flutter create widget test template.

Running `flutter create —with-widget-test` produces a test/widget_test.dart sample widget test.

* Generate widget test bits in flutter create.

* Path fix.

* Added types.

* Skip shell testing on windows.

* formatting fixes

* Update test sample to test the sample app.

* Formatting tweak.
parent c0e98096
...@@ -4,11 +4,15 @@ description: {{description}} ...@@ -4,11 +4,15 @@ description: {{description}}
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
{{#withDriverTest}}
dev_dependencies: dev_dependencies:
flutter_test:
sdk: flutter
{{#withDriverTest}}
flutter_driver: flutter_driver:
sdk: flutter sdk: flutter
{{/withDriverTest}} {{/withDriverTest}}
{{#withPluginHook}} {{#withPluginHook}}
{{pluginProjectName}}: {{pluginProjectName}}:
path: ../ path: ../
......
// This is a basic Flutter widget test.
// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter
// provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to
// find child widgets in the widget tree, read text, and verify that the values of widget properties
// are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../lib/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io' as io;
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
...@@ -45,6 +46,7 @@ void main() { ...@@ -45,6 +46,7 @@ void main() {
'ios/Runner/AppDelegate.m', 'ios/Runner/AppDelegate.m',
'ios/Runner/main.m', 'ios/Runner/main.m',
'lib/main.dart', 'lib/main.dart',
'test/widget_test.dart'
], ],
); );
}); });
...@@ -59,7 +61,7 @@ void main() { ...@@ -59,7 +61,7 @@ void main() {
'ios/Runner/Runner-Bridging-Header.h', 'ios/Runner/Runner-Bridging-Header.h',
'lib/main.dart', 'lib/main.dart',
], ],
<String>[ unexpectedPaths: <String>[
'android/app/src/main/java/com/yourcompany/flutterproject/MainActivity.java', 'android/app/src/main/java/com/yourcompany/flutterproject/MainActivity.java',
'ios/Runner/AppDelegate.h', 'ios/Runner/AppDelegate.h',
'ios/Runner/AppDelegate.m', 'ios/Runner/AppDelegate.m',
...@@ -83,6 +85,7 @@ void main() { ...@@ -83,6 +85,7 @@ void main() {
'example/ios/Runner/main.m', 'example/ios/Runner/main.m',
'example/lib/main.dart', 'example/lib/main.dart',
], ],
plugin: true,
); );
}); });
...@@ -101,13 +104,14 @@ void main() { ...@@ -101,13 +104,14 @@ void main() {
'example/ios/Runner/Runner-Bridging-Header.h', 'example/ios/Runner/Runner-Bridging-Header.h',
'example/lib/main.dart', 'example/lib/main.dart',
], ],
<String>[ unexpectedPaths: <String>[
'android/src/main/java/com/yourcompany/flutterproject/FlutterProjectPlugin.java', 'android/src/main/java/com/yourcompany/flutterproject/FlutterProjectPlugin.java',
'example/android/app/src/main/java/com/yourcompany/flutterprojectexample/MainActivity.java', 'example/android/app/src/main/java/com/yourcompany/flutterprojectexample/MainActivity.java',
'example/ios/Runner/AppDelegate.h', 'example/ios/Runner/AppDelegate.h',
'example/ios/Runner/AppDelegate.m', 'example/ios/Runner/AppDelegate.m',
'example/ios/Runner/main.m', 'example/ios/Runner/main.m',
], ],
plugin: true,
); );
}); });
...@@ -119,10 +123,11 @@ void main() { ...@@ -119,10 +123,11 @@ void main() {
'android/src/main/java/com/bar/foo/flutterproject/FlutterProjectPlugin.java', 'android/src/main/java/com/bar/foo/flutterproject/FlutterProjectPlugin.java',
'example/android/app/src/main/java/com/bar/foo/flutterprojectexample/MainActivity.java', 'example/android/app/src/main/java/com/bar/foo/flutterprojectexample/MainActivity.java',
], ],
<String>[ unexpectedPaths: <String>[
'android/src/main/java/com/yourcompany/flutterproject/FlutterProjectPlugin.java', 'android/src/main/java/com/yourcompany/flutterproject/FlutterProjectPlugin.java',
'example/android/app/src/main/java/com/yourcompany/flutterprojectexample/MainActivity.java', 'example/android/app/src/main/java/com/yourcompany/flutterprojectexample/MainActivity.java',
], ],
plugin: true,
); );
}); });
...@@ -163,6 +168,24 @@ void main() { ...@@ -163,6 +168,24 @@ void main() {
} }
} }
// TODO(pq): enable when sky_shell is available
if (!io.Platform.isWindows) {
// Verify that the sample widget test runs cleanly.
final List<String> args = <String>[
fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')),
'test',
'--no-color',
fs.path.join(projectDir.path, 'test', 'widget_test.dart'),
];
final ProcessResult result = await Process.run(
fs.path.join(dartSdkPath, 'bin', 'dart'),
args,
workingDirectory: projectDir.path,
);
expect(result.exitCode, 0);
}
// Generated Xcode settings // Generated Xcode settings
final String xcodeConfigPath = fs.path.join('ios', 'Flutter', 'Generated.xcconfig'); final String xcodeConfigPath = fs.path.join('ios', 'Flutter', 'Generated.xcconfig');
expectExists(xcodeConfigPath); expectExists(xcodeConfigPath);
...@@ -232,7 +255,7 @@ void main() { ...@@ -232,7 +255,7 @@ void main() {
Future<Null> _createAndAnalyzeProject( Future<Null> _createAndAnalyzeProject(
Directory dir, List<String> createArgs, List<String> expectedPaths, Directory dir, List<String> createArgs, List<String> expectedPaths,
[List<String> unexpectedPaths = const <String>[]]) async { { List<String> unexpectedPaths = const <String>[], bool plugin = false }) async {
Cache.flutterRoot = '../..'; Cache.flutterRoot = '../..';
final CreateCommand command = new CreateCommand(); final CreateCommand command = new CreateCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command); final CommandRunner<Null> runner = createTestCommandRunner(command);
...@@ -247,14 +270,29 @@ Future<Null> _createAndAnalyzeProject( ...@@ -247,14 +270,29 @@ Future<Null> _createAndAnalyzeProject(
for (String path in unexpectedPaths) { for (String path in unexpectedPaths) {
expect(fs.file(fs.path.join(dir.path, path)).existsSync(), false, reason: '$path exists'); expect(fs.file(fs.path.join(dir.path, path)).existsSync(), false, reason: '$path exists');
} }
if (plugin) {
_analyze(dir.path, target: fs.path.join(dir.path, 'lib', 'flutter_project.dart'));
_analyze(fs.path.join(dir.path, 'example'));
} else {
_analyze(dir.path);
}
}
void _analyze(String workingDir, {String target}) {
final String flutterToolsPath = fs.path.absolute(fs.path.join( final String flutterToolsPath = fs.path.absolute(fs.path.join(
'bin', 'bin',
'flutter_tools.dart', 'flutter_tools.dart',
)); ));
final List<String> args = <String>[flutterToolsPath, 'analyze'];
if (target != null)
args.add(target);
final ProcessResult exec = Process.runSync( final ProcessResult exec = Process.runSync(
'$dartSdkPath/bin/dart', '$dartSdkPath/bin/dart',
<String>[flutterToolsPath, 'analyze'], args,
workingDirectory: dir.path, workingDirectory: workingDir,
); );
if (exec.exitCode != 0) { if (exec.exitCode != 0) {
print(exec.stdout); print(exec.stdout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment