测试应该找到一个特定的图标

时间:2019-07-15 14:35:43

标签: testing flutter icons

我如何测试它应该找到特定的图标,例如Icons.visibility? 这是我的测试:

  testWidgets(
      'Should find visibility_off icon',
      (WidgetTester tester) async {
    await _buildApp(tester);
    await tester.pumpAndSettle();
    expect(find.byWidget(Icon(Icons.visibility)), findsOneWidget);
  });

1 个答案:

答案 0 :(得分:2)

byIcon对象上有一个Finder方法。

https://api.flutter.dev/flutter/flutter_test/CommonFinders/byIcon.html

testWidgets('Should find visibility_off icon', (WidgetTester tester) async {
  await _buildApp(tester);
  await tester.pumpAndSettle();
  expect(find.byIcon(Icons.visibility), findsOneWidget);
});