简体   繁体   中英

Sample integration test with Flutter new integration_test?

Sample integration test with Flutter new integration_test ?

  1. First add a dependency in pubspec.yaml under dev
dev_dependencies:
  flutter_test:
    sdk: flutter
  integration_test:
    sdk: flutter
  test: ^1.9.4
  1. Your package should have a structure that looks like this: 在此处输入图像描述

  2. 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));
                                      });
                                    }
  1. Add key like we set in flutter_driver

     appBar: AppBar( title: Text( 'ToDoApp', key: Key("toDoKey"), ), backgroundColor: Colors.brown[400], ),
  2. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM