Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flutter integration test package.
Flutter
import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/[1].dart';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'flutter_test' instead of 'integration_test'.
Misspelling the package name.
✗ Incorrect
The correct import for Flutter integration testing is 'integration_test'.
2fill in blank
mediumComplete the code to initialize the integration test binding.
Flutter
void main() {
final binding = [1].ensureInitialized();
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WidgetsFlutterBinding which is for unit/widget tests.
Forgetting to call ensureInitialized().
✗ Incorrect
IntegrationTestWidgetsFlutterBinding is used to initialize integration testing in Flutter.
3fill in blank
hardFix the error in the test function declaration for integration testing.
Flutter
testWidgets('tap on button changes text', (WidgetTester [1]) async { // test code });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'context' which is not a parameter here.
Using 'widget' or 'test' which are invalid parameter names.
✗ Incorrect
The parameter name for the testWidgets callback is conventionally 'tester'.
4fill in blank
hardFill both blanks to pump the app and wait for animations to settle.
Flutter
await [1].pumpWidget(MyApp()); await [2].pumpAndSettle();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for the same tester object.
Forgetting to await asynchronous calls.
✗ Incorrect
The 'tester' object is used to pump widgets and wait for animations in integration tests.
5fill in blank
hardFill all three blanks to find a button by key, tap it, and verify text change.
Flutter
final button = find.byKey(const Key('[1]')); await tester.tap(button); await tester.[2](); expect(find.text('[3]'), findsOneWidget);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong key strings that don't match the widget.
Forgetting to wait after tapping before checking text.
Expecting wrong text that doesn't appear after tap.
✗ Incorrect
The button key is 'increment', after tapping we wait with pumpAndSettle, then expect the text 'Clicked!'.