热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用Flutter新的integration_test进行示例集成测试?

使用Flutternewintegration_test进行示例集成测试?回答首先在dev下的p

使用 Flutter new integration_test 进行示例集成测试?

回答




  1. 首先在dev下的pubspec.yaml中添加一个依赖

dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
test: ^1.9.4


  1. 您的包应该具有如下所示的结构:


  2. 在 test/test_driver/integration_test.dart

    import'package:integration_test/integration_test_driver.dart';
    Future main() => integrationDriver();


4.在integration_test/foo_test.dart示例中

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. 添加我们在 flutter_driver 中设置的键

    appBar: AppBar(
    title: Text(
    'ToDoApp',
    key: Key("toDoKey"),
    ),
    backgroundColor: Colors.brown[400],
    ),


  2. Foo 最后在你的终端 flutter drive 中运行命令

    --driver=test_driver/integration_test.dart

    --target=integration_test/foo_test.dart


谢谢..快乐飘飘






推荐阅读
author-avatar
手机用户2702935720
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有