0
0
Fluttermobile~10 mins

Widget testing in Flutter - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to pump the widget in the test environment.

Flutter
await tester.[1]Widget(MyApp());
Drag options to blanks, or click blank then click option'
Apump
Brun
Cstart
Dbuild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'runWidget' instead of 'pumpWidget'.
Forgetting to await the method.
2fill in blank
medium

Complete the code to find a widget by its text content.

Flutter
final titleFinder = find.[1]('Welcome');
Drag options to blanks, or click blank then click option'
AbyKey
Btext
CbyType
Dwidget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'byType' when searching by text.
Using 'byKey' without a key.
3fill in blank
hard

Fix the error in the test assertion to check if a widget is found exactly once.

Flutter
expect(find.byType(MyButton), finds[1]Widget);
Drag options to blanks, or click blank then click option'
AOne
BExactlyOne
COneTime
DSingle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ExactlyOne' which is not a valid matcher.
Using 'Single' or 'OneTime' which do not exist.
4fill in blank
hard

Fill both blanks to simulate a tap on a widget found by key and then wait for animations to settle.

Flutter
await tester.tap(find.[1](Key('submit')));
await tester.[2]();
Drag options to blanks, or click blank then click option'
AbyKey
BpumpAndSettle
CbyType
Dpump
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'byType' instead of 'byKey' to find the widget.
Using 'pump' instead of 'pumpAndSettle' after tap.
5fill in blank
hard

Fill all three blanks to write a test that pumps a widget, taps a button by key, and verifies a text appears.

Flutter
await tester.[1]Widget(MyApp());
await tester.tap(find.[2](Key('increment')));
expect(find.[3]('Count: 1'), findsOneWidget);
Drag options to blanks, or click blank then click option'
Apump
BbyKey
Ctext
Dtap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tap' instead of 'pump' to load the widget.
Using 'byType' instead of 'byKey' to find the button.
Using 'byKey' instead of 'text' to find the text.