[英]Running the same flutter test after each other. 1 succeeds and 1 fails
Im starting with creating Flutter tests and running into a problem with 2 tests that are exactly the same, but only 1 succeeds.我从创建 Flutter 测试开始,遇到了 2 个完全相同的测试的问题,但只有 1 个成功。
Gist: https://gist.github.com/Mooibroek/bd6c02e5b56e4b03409ee1839a2e0b23要点: https ://gist.github.com/Mooibroek/bd6c02e5b56e4b03409ee1839a2e0b23
The second one fails with this error:第二个失败并出现此错误:
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)
Line 38 is the line where we assert if the button is found.第 38 行是我们断言是否找到按钮的行。 I added most of the related code in the GIST, let me know if you need more.
我在 GIST 中添加了大部分相关代码,如果您需要更多,请告诉我。
Is it in any way possible that there is some hidden state left from the previous test?是否有可能从之前的测试中留下一些隐藏状态? Or is this not suppose to work.
或者这不应该工作。
I'm using a similar setup where I just duplicated my testWidgets()
.我正在使用类似的设置,我刚刚复制了我的
testWidgets()
。 There shouldn't be ay issues with referencing the same Widget on the test since the second testWidgets()
initializes a new MyApp on tester.pumpWidget()
.由于第二个
testWidgets()
在tester.pumpWidget()
() 上初始化了一个新的 MyApp,所以在测试中引用同一个 Widget 应该没有问题。 Though I'm using integration_test and flutter driver
to launch my tests.虽然我正在使用integration_test和
flutter driver
来启动我的测试。
The tests should run the app on the emulator or physical device if you're using one.如果您使用的是模拟器或物理设备,测试应该在模拟器或物理设备上运行应用程序。 Check if the screen that appears on the second
testWidgets()
is correct.检查第二个
testWidgets()
上出现的屏幕是否正确。 Tap the expected Widget to be found on screen in the emulator.在模拟器的屏幕上点击预期的小部件。 This should show logs on how the tapped Widget can be found in the test.
这应该显示有关如何在测试中找到被点击的 Widget 的日志。 The logs should look similarly to this
日志应该与此类似
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.