作者:手机用户2702935720 | 来源:互联网 | 2023-10-17 13:40
使用 Flutter new integration_test 进行示例集成测试?
回答
- 首先在dev下的pubspec.yaml中添加一个依赖
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
test: ^1.9.4
您的包应该具有如下所示的结构:
在 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));
});
}
添加我们在 flutter_driver 中设置的键
appBar: AppBar(
title: Text(
'ToDoApp',
key: Key("toDoKey"),
),
backgroundColor: Colors.brown[400],
),
Foo 最后在你的终端 flutter drive 中运行命令
--driver=test_driver/integration_test.dart
--target=integration_test/foo_test.dart
谢谢..快乐飘飘