集成测试中的ListView(Flutter)

14ifxucb  于 11个月前  发布在  Flutter
关注(0)|答案(2)|浏览(100)

我还没有找到一个复杂的例子来测试ListViews。
我有一个ListView,它有三个对象Person

Person{
   String name;
   String surname;
}

字符串
在UI中,Person被 Package 在Column中,为namesurname提供了两个Text Widget。
我点击FAB。点击FAB添加新的PersonnameTom和姓ThomsonListView。现在有4个Person的对象。我知道最后一个的数据。
我如何验证,该项目已成功添加?有没有办法检查ListViewlength/count?有没有办法验证最后添加的项目参数?
谢谢!

d4so4syb

d4so4syb1#

widgetList在树中提供了一个匹配的小部件,只需要提到需要测试的Listview的键。

final count = tester
          .widgetList<ListView>(find.byKey(ValueKey("ListViewKey")))
          .length;

字符串

30byixjq

30byixjq2#

我用一个唯一的键 (例如'tile_surname_#') 添加我的ListTile标题。假设你的ListView是用一个名为persons的Person对象数组构建的,你可以尝试这样的操作:

final String valueKey = 'tile_$newPerson.surname_${persons.length}';
    final newPersonFinder = find.byValueKey(valueKey);
    expect(
       await driver.getText(newPersonFinder), valueKey
    );

字符串

相关问题