问题描述
今天,我开始学习Flutter文档的测试。 一切都很好,直到我想查看模拟器上的测试操作。
我的代码是:
testWidgets('tap,drag,and enter text',(WidgetTester tester) async {
await tester.pumpWidget(TodoList());
await tester.enterText(find.byType(TextField),'hi');
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
expect(find.text('hi'),findsOneWidget);
await tester.drag(find.byType(Dismissible),Offset(500.0,0.0));
await tester.pumpAndSettle();
expect(find.text('hi'),findsNothing);
});
我遵循了文档,一切都很好,我对此方法进行了运行,并且工作正常,没有错误。但是,当我想查看仿真器上的测试时,我在终端flutter run test/widget_test.dart
中键入了此命令。然后仿真器开始查看结果,但在TextField
中写了“ hi”后停止运行,然后出现此异常。
If WidgetTester.takeException is called,the above exception will be ignored. If it is not,then the above
exception will be dumped when another exception is caught by the framework or when the test ends,whichever happens first,and
then the test will fail due to having not caught or expected the exception.)
我搜索了很多,然后找到了这个解决方案:
expect(tester.takeException(),isInstanceOf<UnrecognizedTermException>());
我按如下方式将其添加到方法中:
testWidgets('tap,'hi');
// added here
expect(tester.takeException(),isInstanceOf<UnrecognizedTermException>());
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
expect(find.text('hi'),findsNothing);
});
我将此添加到了我的方法中,但是UnrecognizedTermException
告诉我不是类型,因此不能用作类型参数。
我希望我清楚地说明了这个问题,感谢任何人都可以帮助我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)