繁体   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