如何测试覆盖?
How to test overlay?
我正在测试点击按钮时显示的叠加层。叠加层包含 TextFormField(查看演示 here)。
我在犹豫是否应该使用更高级的测试框架。
这是代码:
await tester.tap(find.byType(IconButton));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextFormField), 'hi');
测试在最后一行失败并显示消息 Bad state: No element
。
覆盖层似乎丢失了。有什么建议吗?
要完全泵叠加,pumpAndSettle
应调用两次。
黄金屏幕截图在调试时也是非常有用的功能:
await tester.tap(find.byType(IconButton));
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await expectLater(
find.byType(MaterialApp),
matchesGoldenFile('overlay.png'),
);
await tester.enterText(find.byType(TextFormField), 'hi');
运行 flutter test --update-goldens
生成金色。
我正在测试点击按钮时显示的叠加层。叠加层包含 TextFormField(查看演示 here)。
我在犹豫是否应该使用更高级的测试框架。
这是代码:
await tester.tap(find.byType(IconButton));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextFormField), 'hi');
测试在最后一行失败并显示消息 Bad state: No element
。
覆盖层似乎丢失了。有什么建议吗?
要完全泵叠加,pumpAndSettle
应调用两次。
黄金屏幕截图在调试时也是非常有用的功能:
await tester.tap(find.byType(IconButton));
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await expectLater(
find.byType(MaterialApp),
matchesGoldenFile('overlay.png'),
);
await tester.enterText(find.byType(TextFormField), 'hi');
运行 flutter test --update-goldens
生成金色。