mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Update plugin test template. (#13516)
* Update plugin test template. * Add flutter test run verification. * Tweak and test runs for package projects.
This commit is contained in:
parent
5e18c07614
commit
3346c5c736
@ -9,6 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
|
|
||||||
import 'package:{{projectName}}/main.dart';
|
import 'package:{{projectName}}/main.dart';
|
||||||
|
|
||||||
|
{{^withPluginHook}}
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
// Build our app and trigger a frame.
|
// Build our app and trigger a frame.
|
||||||
@ -27,3 +28,20 @@ void main() {
|
|||||||
expect(find.text('1'), findsOneWidget);
|
expect(find.text('1'), findsOneWidget);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
{{/withPluginHook}}
|
||||||
|
{{#withPluginHook}}
|
||||||
|
void main() {
|
||||||
|
testWidgets('Verify Platform version', (WidgetTester tester) async {
|
||||||
|
// Build our app and trigger a frame.
|
||||||
|
await tester.pumpWidget(new MyApp());
|
||||||
|
|
||||||
|
// Verify that platform version is retrieved.
|
||||||
|
expect(
|
||||||
|
find.byWidgetPredicate(
|
||||||
|
(Widget widget) =>
|
||||||
|
widget is Text && widget.data.startsWith('Running on:'),
|
||||||
|
),
|
||||||
|
findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{{/withPluginHook}}
|
||||||
|
@ -47,7 +47,7 @@ void main() {
|
|||||||
|
|
||||||
// Verify that we create a project that is well-formed.
|
// Verify that we create a project that is well-formed.
|
||||||
testUsingContext('project', () async {
|
testUsingContext('project', () async {
|
||||||
return _createAndAnalyzeProject(
|
await _createAndAnalyzeProject(
|
||||||
projectDir,
|
projectDir,
|
||||||
<String>[],
|
<String>[],
|
||||||
<String>[
|
<String>[
|
||||||
@ -60,6 +60,7 @@ void main() {
|
|||||||
'flutter_project.iml',
|
'flutter_project.iml',
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
return _runFlutterTest(projectDir);
|
||||||
}, timeout: allowForRemotePubInvocation);
|
}, timeout: allowForRemotePubInvocation);
|
||||||
|
|
||||||
testUsingContext('kotlin/swift project', () async {
|
testUsingContext('kotlin/swift project', () async {
|
||||||
@ -82,7 +83,7 @@ void main() {
|
|||||||
}, timeout: allowForCreateFlutterProject);
|
}, timeout: allowForCreateFlutterProject);
|
||||||
|
|
||||||
testUsingContext('package project', () async {
|
testUsingContext('package project', () async {
|
||||||
return _createAndAnalyzeProject(
|
await _createAndAnalyzeProject(
|
||||||
projectDir,
|
projectDir,
|
||||||
<String>['--template=package'],
|
<String>['--template=package'],
|
||||||
<String>[
|
<String>[
|
||||||
@ -106,10 +107,11 @@ void main() {
|
|||||||
'test/widget_test.dart',
|
'test/widget_test.dart',
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
return _runFlutterTest(projectDir);
|
||||||
}, timeout: allowForRemotePubInvocation);
|
}, timeout: allowForRemotePubInvocation);
|
||||||
|
|
||||||
testUsingContext('plugin project', () async {
|
testUsingContext('plugin project', () async {
|
||||||
return _createAndAnalyzeProject(
|
await _createAndAnalyzeProject(
|
||||||
projectDir,
|
projectDir,
|
||||||
<String>['--template=plugin'],
|
<String>['--template=plugin'],
|
||||||
<String>[
|
<String>[
|
||||||
@ -126,6 +128,7 @@ void main() {
|
|||||||
],
|
],
|
||||||
plugin: true,
|
plugin: true,
|
||||||
);
|
);
|
||||||
|
return _runFlutterTest(projectDir.childDirectory('example'));
|
||||||
}, timeout: allowForRemotePubInvocation);
|
}, timeout: allowForRemotePubInvocation);
|
||||||
|
|
||||||
testUsingContext('kotlin/swift plugin project', () async {
|
testUsingContext('kotlin/swift plugin project', () async {
|
||||||
@ -212,19 +215,7 @@ void main() {
|
|||||||
// TODO(pq): enable when sky_shell is available
|
// TODO(pq): enable when sky_shell is available
|
||||||
if (!io.Platform.isWindows) {
|
if (!io.Platform.isWindows) {
|
||||||
// Verify that the sample widget test runs cleanly.
|
// Verify that the sample widget test runs cleanly.
|
||||||
final List<String> args = <String>[]
|
await _runFlutterTest(projectDir, target: fs.path.join(projectDir.path, 'test', 'widget_test.dart'));
|
||||||
..addAll(dartVmFlags)
|
|
||||||
..add(fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')))
|
|
||||||
..add('test')
|
|
||||||
..add('--no-color')
|
|
||||||
..add(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
|
||||||
@ -395,6 +386,32 @@ Future<Null> _analyzeProject(String workingDir, {String target}) async {
|
|||||||
expect(exec.exitCode, 0);
|
expect(exec.exitCode, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Null> _runFlutterTest(Directory workingDir, {String target}) async {
|
||||||
|
final String flutterToolsPath = fs.path.absolute(fs.path.join(
|
||||||
|
'bin',
|
||||||
|
'flutter_tools.dart',
|
||||||
|
));
|
||||||
|
|
||||||
|
final List<String> args = <String>[]
|
||||||
|
..addAll(dartVmFlags)
|
||||||
|
..add(flutterToolsPath)
|
||||||
|
..add('test')
|
||||||
|
..add('--no-color');
|
||||||
|
if (target != null)
|
||||||
|
args.add(target);
|
||||||
|
|
||||||
|
final ProcessResult exec = await Process.run(
|
||||||
|
'$dartSdkPath/bin/dart',
|
||||||
|
args,
|
||||||
|
workingDirectory: workingDir.path,
|
||||||
|
);
|
||||||
|
if (exec.exitCode != 0) {
|
||||||
|
print(exec.stdout);
|
||||||
|
print(exec.stderr);
|
||||||
|
}
|
||||||
|
expect(exec.exitCode, 0);
|
||||||
|
}
|
||||||
|
|
||||||
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
||||||
|
|
||||||
/// A ProcessManager that invokes a real process manager, but keeps
|
/// A ProcessManager that invokes a real process manager, but keeps
|
||||||
|
Loading…
Reference in New Issue
Block a user