Unverified Commit d047d108 authored by Dan Field's avatar Dan Field Committed by GitHub

Add integration_test template to create template (#70240)

parent 2520d53e
// This is a basic Flutter integration 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 'package:integration_test/integration_test.dart';
import 'package:{{projectName}}/main.dart' as app;
void main() => run(_testMain);
void _testMain() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
app.main();
// Trigger a frame.
await tester.pumpAndSettle();
{{^withPluginHook}}
// 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);
{{/withPluginHook}}
{{#withPluginHook}}
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data.startsWith('Running on:'),
),
findsOneWidget,
);
{{/withPluginHook}}
});
}
// This file is provided as a convenience for running integration tests via the
// flutter drive command.
//
// flutter drive --driver integration_test/driver.dart --target integration_test/app_test.dart
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() => integrationDriver();
...@@ -43,6 +43,8 @@ dependencies: ...@@ -43,6 +43,8 @@ dependencies:
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
integration_test:
sdk: flutter
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
"templates/app/android.tmpl/gradle/wrapper/gradle-wrapper.properties", "templates/app/android.tmpl/gradle/wrapper/gradle-wrapper.properties",
"templates/app/android.tmpl/gradle.properties.tmpl", "templates/app/android.tmpl/gradle.properties.tmpl",
"templates/app/android.tmpl/settings.gradle", "templates/app/android.tmpl/settings.gradle",
"templates/app/integration_test/app_test.dart.tmpl",
"templates/app/integration_test/driver.dart.tmpl",
"templates/app/ios-objc.tmpl/Runner/AppDelegate.h", "templates/app/ios-objc.tmpl/Runner/AppDelegate.h",
"templates/app/ios-objc.tmpl/Runner/AppDelegate.m", "templates/app/ios-objc.tmpl/Runner/AppDelegate.m",
"templates/app/ios-objc.tmpl/Runner/main.m", "templates/app/ios-objc.tmpl/Runner/main.m",
......
...@@ -299,6 +299,8 @@ void main() { ...@@ -299,6 +299,8 @@ void main() {
'ios/Runner/main.m', 'ios/Runner/main.m',
'lib/main.dart', 'lib/main.dart',
'test/widget_test.dart', 'test/widget_test.dart',
'integration_test/app_test.dart',
'integration_test/driver.dart',
], ],
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -364,6 +366,8 @@ void main() { ...@@ -364,6 +366,8 @@ void main() {
'ios/Runner/main.m', 'ios/Runner/main.m',
'lib/main.dart', 'lib/main.dart',
'test/widget_test.dart', 'test/widget_test.dart',
'integration_test/app_test.dart',
'integration_test/driver.dart',
], ],
); );
return _runFlutterTest(projectDir); return _runFlutterTest(projectDir);
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import '../src/common.dart';
import 'test_utils.dart';
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'flutter.bat' : 'flutter');
void main() {
Directory tempDir;
setUpAll(() {
tempDir = createResolvedTempDirectorySync('int_test.');
});
tearDownAll(() {
tryToDelete(tempDir);
});
testWithoutContext('flutter project default integration_test smoke test', () async {
const String projectName = 'integration_test_sample';
ProcessResult result = await processManager.run(
<String>[
flutterBin,
'create',
projectName,
],
workingDirectory: tempDir.path,
);
expect(result.exitCode, 0);
final Directory projectDir = tempDir.childDirectory(projectName);
expect(projectDir.existsSync(), true);
final Directory integrationTestDir = projectDir.childDirectory('integration_test');
expect(integrationTestDir.existsSync(), true);
expect(integrationTestDir.childFile('driver.dart').existsSync(), true);
expect(integrationTestDir.childFile('app_test.dart').existsSync(), true);
result = await processManager.run(
<String>[
flutterBin,
'drive',
'-d', 'flutter-tester',
'--driver', 'integration_test/driver.dart',
'-t', 'integration_test/app_test.dart',
],
workingDirectory: projectDir.path,
);
if (result.exitCode != 0) {
print('================================= STDOUT =======================================');
print(result.stdout);
print('================================= STDERR =======================================');
print(result.stderr);
fail('flutter drive failed, see output.');
}
});
}
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