- Add test package to
pubspec.yaml
- Old:
flutter_driver:
sdk: flutter
- New:
integration_test:
sdk: flutter
See (Migrating from flutter_driver)[https://docs.flutter.dev/testing/integration-tests/migration] for more information.
-
Create
test_driver
andintegration_test
directory from project root dir -
Create
test_driver/integration_test.dart
file:
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() => integrationDriver();
- Create
integration_test/app_test.dart
file:
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:reproduce_issues_test/main.dart' as app;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('end-to-end test', () {
testWidgets('tap on the floating action button, verify counter',
(tester) async {
app.main();
await tester.pumpAndSettle();
// Verify the counter starts at 0.
expect(find.text('0'), findsOneWidget);
// Finds the floating action button to tap on.
final Finder fab = find.byTooltip('Increment');
// Emulate a tap on the floating action button.
await tester.tap(fab);
// Trigger a frame.
await tester.pumpAndSettle();
// Verify the counter increments by 1.
expect(find.text('1'), findsOneWidget);
});
});
}
- Run integration test
- Old flutter drive test:
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart
- New flutter test:
flutter test integration_test/app_test.dart