Sample integration test with Flutter new integration_test ?
Asked
Active
Viewed 1,073 times
1 Answers
5
- First add a dependency in pubspec.yaml under dev
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
test: ^1.9.4
in test/test_driver/integration_test.dart
import'package:integration_test/integration_test_driver.dart'; Future<void> main() => integrationDriver();
4.In integration_test/foo_test.dart example
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets("Sign in test example", (WidgetTester tester) async {
final Finder signInEmailField = find.byKey(Key('signInEmailField'));
final Finder signInPasswordField = find.byKey(Key('signInPasswordField'));
final Finder signInSaveButton = find.byKey(Key('signInSaveButton'));
await tester.pumpWidget(MyApp());
await tester.pumpAndSettle();
await tester.tap(find.byKey(Key('signInEmailField')));
await tester.enterText(signInEmailField, "paras@gmail.com");
await tester.tap(signInPasswordField);
await tester.enterText(signInPasswordField, "123456");
await tester.tap(signInSaveButton);
print("button tapped");
await tester.pumpAndSettle(Duration(seconds: 1));
expect(
find.byWidgetPredicate((widget) =>
widget is AppBar &&
widget.title is Text &&
(widget.title as Text).data.startsWith("ToDoApp")),
findsOneWidget);
await tester.pumpAndSettle(Duration(seconds: 1));
});
}
Add key like we set in flutter_driver
appBar: AppBar( title: Text( 'ToDoApp', key: Key("toDoKey"), ), backgroundColor: Colors.brown[400], ),
Foo last run the command in your terminal flutter drive
--driver=test_driver/integration_test.dart
--target=integration_test/foo_test.dart
Thanks.. happy Fluttering

Nils Reichardt
- 3,195
- 2
- 18
- 28

Paras Arora
- 605
- 6
- 12
-
1I have followed your tutorial, it was very helpful, thank you. Have you experienced [my issue](https://stackoverflow.com/q/65528412/3935156) before? – BeniaminoBaggins Jan 02 '21 at 01:21
-
hi, in 4th step, whats `MyApp()`? is that the view that we want to test or something else? – thekucays Sep 14 '22 at 10:12