Challenge - 5 Problems
Integration Testing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the output of this Flutter integration test snippet?
Consider this Flutter integration test code that taps a button and expects a text change. What will the test find after tapping the button?
Flutter
testWidgets('Button tap changes text', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp(home: Scaffold(body: StatefulBuilder( builder: (context, setState) { String text = 'Before'; return Column(children: [ Text(text, key: Key('displayText')), ElevatedButton( onPressed: () => setState(() => text = 'After'), child: Text('Tap me'), ), ]); }, ))); expect(find.text('Before'), findsOneWidget); await tester.tap(find.byType(ElevatedButton)); await tester.pump(); expect(find.text('After'), findsOneWidget); });
Attempts:
2 left
💡 Hint
Remember how StatefulBuilder works and when the state variable is reset.
✗ Incorrect
The variable 'text' is reinitialized to 'Before' every build, so setState changes a local variable that resets immediately. The text never updates to 'After'.
❓ lifecycle
intermediate1:30remaining
Which lifecycle method is best to initialize integration test bindings in Flutter?
In Flutter integration tests, which method should you call to ensure the test environment is ready before running tests?
Attempts:
2 left
💡 Hint
Initialization should happen once before all tests.
✗ Incorrect
IntegrationTestWidgetsFlutterBinding.ensureInitialized() should be called inside setUpAll() to prepare the test environment once before all tests run.
🔧 Debug
advanced1:30remaining
What error does this integration test produce?
This Flutter integration test tries to find a widget by key but fails. What error will it raise?
Flutter
testWidgets('Find widget by key', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp(home: Text('Hello'))); expect(find.byKey(Key('missingKey')), findsOneWidget); });
Attempts:
2 left
💡 Hint
Check what happens when find.byKey does not find any widget.
✗ Incorrect
The test expects to find one widget with the key 'missingKey' but none exists, so it throws a TestFailure.
advanced
2:00remaining
What is the final screen shown after this integration test navigation?
Given this Flutter integration test code that taps a button to navigate, which screen is visible at the end?
Flutter
testWidgets('Navigate to second screen', (WidgetTester tester) async { await tester.pumpWidget(MaterialApp( home: Scaffold( body: Builder(builder: (context) { return ElevatedButton( onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (_) => Scaffold(body: Center(child: Text('Second Screen'))))), child: Text('Go'), ); }), ), )); await tester.tap(find.text('Go')); await tester.pumpAndSettle(); expect(find.text('Second Screen'), findsOneWidget); });
Attempts:
2 left
💡 Hint
pumpAndSettle waits for navigation animations to finish.
✗ Incorrect
After tapping the button, Navigator.push navigates to a new screen showing 'Second Screen'. pumpAndSettle waits for the transition to complete.
🧠 Conceptual
expert2:30remaining
Which statement about Flutter integration testing is true?
Choose the correct statement about Flutter integration tests compared to widget tests.
Attempts:
2 left
💡 Hint
Think about the scope and environment of integration tests.
✗ Incorrect
Integration tests run on real devices or emulators and test the entire app including platform-specific features, unlike widget tests which are more isolated.