在测试环境下,为了定位 widgets,我们需要用到 Finder 类。我们可以编写自己的 finder 类,不过通常使用 flutter_test package 提供的工具来定位 widgets 更加方便。
To locate widgets in a test environment, use the Finder
classes. While it’s possible to write your own Finder classes,
it’s generally more convenient to locate widgets using the tools
provided by the flutter_test package.
运行 widget 测试,在执行 flutter run 的时候,你还可以与屏幕进行交互点击,
Flutter 工具会输出建议的 [Finder][]。
During a flutter run session on a widget test, you can also
interactively tap parts of the screen for the Flutter tool to
print the suggested [Finder].
下面,我们来看看 flutter_test package 提供的 find
常量并演示如何使用其所提供的 Finders。如需查看完整的 finders 的列表,请参阅 CommonFinders 文档。
This recipe looks at the find constant provided by
the flutter_test package, and demonstrates how
to work with some of the Finders it provides.
For a full list of available finders,
see the CommonFinders documentation.
如果你还不熟悉 Widget 测试和 Finder 类使用方法,请参阅 在 Flutter 里做集成测试。
If you’re unfamiliar with widget testing and the role of
Finder classes,
review the Introduction to widget testing reci