簡體   English   中英

集成測試中的 ListView (Flutter)

[英]ListView in integration test (Flutter)

我還沒有找到用於測試 ListViews 的復雜示例。 例子。

我有一個 ListView,它有三個對象Person

Person{
   String name;
   String surname;
}

在 UI 中, Person被包裹在Column中,為他們提供了namesurname兩個Text Widget。

我點擊FAB。 單擊 FAB 將name Tom和姓氏Thomson的新Person添加到ListView 現在有 4 個Person對象。 我知道最后一個的數據。

如何驗證該項目已成功添加? 有沒有辦法檢查ListViewlength/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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM