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.
This commit is contained in:
@@ -4,11 +4,15 @@ description: {{description}}
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
{{#withDriverTest}}
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
{{#withDriverTest}}
|
||||
flutter_driver:
|
||||
sdk: flutter
|
||||
{{/withDriverTest}}
|
||||
|
||||
{{#withPluginHook}}
|
||||
{{pluginProjectName}}:
|
||||
path: ../
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
@@ -45,6 +46,7 @@ void main() {
|
||||
'ios/Runner/AppDelegate.m',
|
||||
'ios/Runner/main.m',
|
||||
'lib/main.dart',
|
||||
'test/widget_test.dart'
|
||||
],
|
||||
);
|
||||
});
|
||||
@@ -59,7 +61,7 @@ void main() {
|
||||
'ios/Runner/Runner-Bridging-Header.h',
|
||||
'lib/main.dart',
|
||||
],
|
||||
<String>[
|
||||
unexpectedPaths: <String>[
|
||||
'android/app/src/main/java/com/yourcompany/flutterproject/MainActivity.java',
|
||||
'ios/Runner/AppDelegate.h',
|
||||
'ios/Runner/AppDelegate.m',
|
||||
@@ -83,6 +85,7 @@ void main() {
|
||||
'example/ios/Runner/main.m',
|
||||
'example/lib/main.dart',
|
||||
],
|
||||
plugin: true,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -101,13 +104,14 @@ void main() {
|
||||
'example/ios/Runner/Runner-Bridging-Header.h',
|
||||
'example/lib/main.dart',
|
||||
],
|
||||
<String>[
|
||||
unexpectedPaths: <String>[
|
||||
'android/src/main/java/com/yourcompany/flutterproject/FlutterProjectPlugin.java',
|
||||
'example/android/app/src/main/java/com/yourcompany/flutterprojectexample/MainActivity.java',
|
||||
'example/ios/Runner/AppDelegate.h',
|
||||
'example/ios/Runner/AppDelegate.m',
|
||||
'example/ios/Runner/main.m',
|
||||
],
|
||||
plugin: true,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -119,10 +123,11 @@ void main() {
|
||||
'android/src/main/java/com/bar/foo/flutterproject/FlutterProjectPlugin.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',
|
||||
'example/android/app/src/main/java/com/yourcompany/flutterprojectexample/MainActivity.java',
|
||||
],
|
||||
plugin: true,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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
|
||||
final String xcodeConfigPath = fs.path.join('ios', 'Flutter', 'Generated.xcconfig');
|
||||
expectExists(xcodeConfigPath);
|
||||
@@ -232,7 +255,7 @@ void main() {
|
||||
|
||||
Future<Null> _createAndAnalyzeProject(
|
||||
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 = '../..';
|
||||
final CreateCommand command = new CreateCommand();
|
||||
final CommandRunner<Null> runner = createTestCommandRunner(command);
|
||||
@@ -247,14 +270,29 @@ Future<Null> _createAndAnalyzeProject(
|
||||
for (String path in unexpectedPaths) {
|
||||
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(
|
||||
'bin',
|
||||
'flutter_tools.dart',
|
||||
));
|
||||
|
||||
final List<String> args = <String>[flutterToolsPath, 'analyze'];
|
||||
if (target != null)
|
||||
args.add(target);
|
||||
|
||||
final ProcessResult exec = Process.runSync(
|
||||
'$dartSdkPath/bin/dart',
|
||||
<String>[flutterToolsPath, 'analyze'],
|
||||
workingDirectory: dir.path,
|
||||
args,
|
||||
workingDirectory: workingDir,
|
||||
);
|
||||
if (exec.exitCode != 0) {
|
||||
print(exec.stdout);
|
||||
|
||||
Reference in New Issue
Block a user