[英]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.