Flutter

Widget Testing

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

18 câu hỏi phỏng vấn·
Mid-Level
1

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

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Flutter cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí