我从创建颤振测试开始,在两个完全相同的测试中遇到了一个问题,但只有一个成功了。
要点:https://gist.github.com/Mooibroek/bd6c02e5b56e4b03409ee1839a2e0b23
第二个错误失败:
The following TestFailure object was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: ?:<zero widgets with widget matching predicate (Closure: (dynamic) => bool) (ignoring
offstage widgets)>
Which: means none were found but one was expected
When the exception was thrown, this was the stack:
#4 main.<anonymous closure> (file:///Users/nicepants/Projects/flutter/generic_flutter/test/register_test.dart:38:5)
<asynchronous suspension>
#5 testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:108:25)第38行是我们断言是否找到按钮的行。我在GIST中添加了大部分相关代码,如果需要更多信息,请告诉我。
以前的测试是否有可能留下一些隐藏的状态?或者这不应该起作用。
发布于 2022-07-18 18:29:36
我正在使用类似的设置,我只是复制了我的testWidgets()。在测试中引用相同的Widget不应该有什么问题,因为第二个testWidgets()在tester.pumpWidget()上初始化了一个新的MyApp。虽然我使用测试和flutter driver来启动我的测试。
测试应该在模拟器或物理设备上运行,如果你使用的话。检查显示在第二个testWidgets()上的屏幕是否正确。点击预期的Widget将在屏幕上找到在模拟器中。这应该会显示如何在测试中找到被点击的Widget的日志。日志应该类似于以下内容

https://stackoverflow.com/questions/56824896
复制相似问题