[英]ListView in integration test (Flutter)
I haven't found a complex examples for testing ListViews.我还没有找到用于测试 ListViews 的复杂示例。 Example.例子。
I have a ListView, which has three objects Person
.我有一个 ListView,它有三个对象Person
。
Person{
String name;
String surname;
}
In UI, Person
is wrapped in Column
, giving them two Text
Widgets for name
and surname
.在 UI 中, Person
被包裹在Column
中,为他们提供了name
和surname
两个Text
Widget。
I click on FAB.我点击FAB。 Clicking on FAB adds new Person
with name
Tom
and surname Thomson
to the ListView
.单击 FAB 将name
Tom
和姓氏Thomson
的新Person
添加到ListView
。 Now there are 4 objects of Person
.现在有 4 个Person
对象。 And I know data of the last one.我知道最后一个的数据。
How can I validate, that item was successfully added?如何验证该项目已成功添加? Is there a way to check length/count
of ListView
?有没有办法检查ListView
的length/count
? Is there a way to validate last added item params?有没有办法验证最后添加的项目参数?
Appreciate!欣赏!
I add my ListTile titles with a unique key (ex. 'tile_surname_#') .我使用唯一键(ex. 'tile_surname_#')添加我的 ListTile 标题。 Assuming your ListView is built with an array of Person objects called persons, you can try something like:假设您的 ListView 是使用名为 Person 的 Person 对象数组构建的,您可以尝试以下操作:
final String valueKey = 'tile_$newPerson.surname_${persons.length}';
final newPersonFinder = find.byValueKey(valueKey);
expect(
await driver.getText(newPersonFinder), valueKey
);
widgetList
provides a matching widget in the tree, just need to mention key of Listview
which required to test. widgetList
在树中提供了一个匹配的小部件,只需要提到需要测试的Listview
的 key。
final count = tester
.widgetList<ListView>(find.byKey(ValueKey("ListViewKey")))
.length;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.