[英]ListView in integration test (Flutter)
我还没有找到用于测试 ListViews 的复杂示例。 例子。
我有一个 ListView,它有三个对象Person
。
Person{
String name;
String surname;
}
在 UI 中, Person
被包裹在Column
中,为他们提供了name
和surname
两个Text
Widget。
我点击FAB。 单击 FAB 将name
Tom
和姓氏Thomson
的新Person
添加到ListView
。 现在有 4 个Person
对象。 我知道最后一个的数据。
如何验证该项目已成功添加? 有没有办法检查ListView
的length/count
? 有没有办法验证最后添加的项目参数?
欣赏!
我使用唯一键(ex. 'tile_surname_#')添加我的 ListTile 标题。 假设您的 ListView 是使用名为 Person 的 Person 对象数组构建的,您可以尝试以下操作:
final String valueKey = 'tile_$newPerson.surname_${persons.length}';
final newPersonFinder = find.byValueKey(valueKey);
expect(
await driver.getText(newPersonFinder), valueKey
);
widgetList
在树中提供了一个匹配的小部件,只需要提到需要测试的Listview
的 key。
final count = tester
.widgetList<ListView>(find.byKey(ValueKey("ListViewKey")))
.length;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.