0
0
Fluttermobile~20 mins

Integration testing in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Integration Testing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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);
});
AThe test fails because the text never changes from 'Before'.
BThe test fails because the button is not found.
CThe test throws a runtime error due to setState used incorrectly.
DThe test passes because the text changes from 'Before' to 'After' after tapping.
Attempts:
2 left
💡 Hint
Remember how StatefulBuilder works and when the state variable is reset.
lifecycle
intermediate
1: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?
AsetUp() with runApp()
BtearDownAll() with runApp()
CtearDown() with IntegrationTestWidgetsFlutterBinding.ensureInitialized()
DsetUpAll() with IntegrationTestWidgetsFlutterBinding.ensureInitialized()
Attempts:
2 left
💡 Hint
Initialization should happen once before all tests.
🔧 Debug
advanced
1: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);
});
ATestFailure: Expected to find one matching node in the widget tree but found none.
BNoSuchMethodError: The method 'byKey' was called on null.
CTimeoutException: Widget not found within time limit.
DSyntaxError: Missing semicolon.
Attempts:
2 left
💡 Hint
Check what happens when find.byKey does not find any widget.
navigation
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);
});
AThe screen still shows the button labeled 'Go'.
BThe screen shows the text 'Second Screen'.
CThe test fails because Navigator.push is not awaited.
DThe test throws an exception due to missing MaterialApp.
Attempts:
2 left
💡 Hint
pumpAndSettle waits for navigation animations to finish.
🧠 Conceptual
expert
2:30remaining
Which statement about Flutter integration testing is true?
Choose the correct statement about Flutter integration tests compared to widget tests.
AIntegration tests do not support asynchronous operations and must be synchronous.
BIntegration tests only test individual widgets in isolation without platform dependencies.
CIntegration tests run on real devices or emulators and test the full app including platform channels.
DIntegration tests cannot simulate user gestures like taps or scrolls.
Attempts:
2 left
💡 Hint
Think about the scope and environment of integration tests.