Flutter

Widget Testing

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

18 mülakat soruları·
Mid-Level
1

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

Cevap

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?

Cevap

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?

Cevap

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 mülakat soruları

Bir sonraki mülakatın için Flutter'de uzmanlaş

Tüm sorulara, flashcards'a, teknik testlere, code review alıştırmalarına ve mülakat simülatörlerine eriş.

Ücretsiz başla