Flutter

Widget Testing

flutter_test, testWidgets, find, pump, WidgetTester, golden tests, integration tests

18 面接問題·
Mid-Level
1

Which package should be used to write widget tests in Flutter?

回答

The flutter_test package is the official package for writing widget tests in Flutter. It is automatically included in the Flutter SDK and provides all the necessary functions and classes to test widgets, such as testWidgets, find, pump and WidgetTester. This package extends Dart's test package with Flutter-specific features.

2

Which function should be used to define a widget test in Flutter?

回答

The testWidgets function is specifically designed for testing Flutter widgets. It provides a WidgetTester as a parameter to the callback which allows interaction with the widget under test. Unlike test() used for unit tests, testWidgets automatically manages the binding framework needed to render widgets and interact with them.

3

How to find a widget by its text in a Flutter test?

回答

The find class provides several methods to locate widgets, including find.text() which searches for a widget containing exactly the specified text. This is one of the most commonly used finders as it allows easily verifying the presence of text on screen. Other common finders include find.byType(), find.byKey() and find.byIcon().

4

What is the difference between pump() and pumpAndSettle() in widget tests?

5

How to simulate a tap on a button in a Flutter widget test?

+15 面接問題

次の面接に向けてFlutterをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める