Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a simple test that checks if the app title is correct.
Flutter
testWidgets('App has correct title', (WidgetTester tester) async { await tester.pumpWidget(MyApp()); expect(find.text([1]), findsOneWidget); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong title string that does not match the app's title.
Forgetting to wrap the title in quotes.
✗ Incorrect
The app's default title is 'Flutter Demo Home Page', so the test should look for this exact text.
2fill in blank
mediumComplete the code to pump the widget and trigger a frame in the test.
Flutter
await tester.[1](MyApp()); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like buildWidget or renderWidget.
Confusing pumpWidget with other test methods.
✗ Incorrect
In Flutter tests, pumpWidget is used to load and render the widget tree.
3fill in blank
hardFix the error in the test assertion to check if a button with text 'Click Me' exists.
Flutter
expect(find.text([1]), findsOneWidget); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different button text than the one in the app.
Forgetting to put the text inside quotes.
✗ Incorrect
The button text to find is 'Click Me', so the test must look for this exact string.
4fill in blank
hardFill both blanks to write a test that taps a button and verifies a counter increments.
Flutter
await tester.tap(find.text([1])); await tester.[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong button label like 'Decrement'.
Calling pumpWidget instead of pump after tap.
✗ Incorrect
The test taps the button labeled 'Increment' and then calls pump() to rebuild the widget tree.
5fill in blank
hardFill all three blanks to write a test that verifies the counter text updates after tapping.
Flutter
expect(find.text('[1]'), findsOneWidget); await tester.tap(find.byIcon([2])); await tester.[3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong initial counter value.
Using the wrong icon or forgetting to call pump().
✗ Incorrect
Initially, the counter shows '0'. The test taps the add icon button and calls pump() to update the UI.