Set up an integration test for a multi-screen login flow
This tests your grasp of integration_test's device runtime versus headless widget tests. A strong answer covers the integration_test directory, ensureInitialized, driving a login flow end-to-end on device.
WHAT THIS TESTS: This question evaluates whether you can architect an end-to-end test in Flutter that exercises real device runtime behavior rather than a headless environment. The interviewer wants to see that you understand the integration_test package's role, the required binding initialization, directory conventions, and the fundamental runtime differences between integration tests and standard widget tests. At the senior level, you should also demonstrate awareness of test data seeding, cleanup, and when on-device execution is strictly necessary.
A GOOD ANSWER COVERS: A strong response hits four things in order. First, file placement and dependencies: tests live in an integration_test directory at project root and the package is listed under dev_dependencies. Second, binding setup: the test main must call IntegrationTestWidgetsFlutterBinding.ensureInitialized before any testWidgets calls so the framework binds to the actual device runtime instead of the headless test environment. Third, flow authoring: you drive the login flow with tester.enterText for credentials, tester.tap for buttons, and tester.pumpAndSettle to wait for navigation and network transitions across multiple screens. Fourth, execution model: you run the suite with flutter test integration_test against a connected device or emulator, which means platform channels, plugins, and OS gestures execute for real rather than being mocked or absent.
COMMON WRONG ANSWERS: Candidates often place integration tests inside the test folder alongside unit and widget tests, which is incorrect. Another red flag is initializing WidgetsFlutterBinding or omitting the binding call entirely, causing tests to crash or behave unpredictably on device. Some engineers claim integration tests are just slow widget tests and do not realize they run on a real device or emulator with a live engine. Confusing the legacy flutter drive workflow with the modern flutter test integration_test command also signals outdated knowledge.
LIKELY FOLLOW-UPS: Interviewers often push deeper by asking how you seed a test user before the login flow or reset app state between runs. They may ask how to handle flakiness from asynchronous network calls or animations during pumpAndSettle. Another common angle is when to stop writing integration tests and rely on widget tests instead, or how to integrate the suite into CI on Firebase Test Lab or similar device farms.
ONE CONCRETE EXAMPLE: Imagine testing a login flow that navigates to a dashboard. You begin by pumping MyApp with tester.pumpWidget. Next, you enter username@example.com into the username field using tester.enterText and the same for the password field. You tap the login button with tester.tap and await tester.pumpAndSettle to handle the async validation and route transition. Finally, you assert that find.text Welcome back appears exactly once on the new screen, confirming the multi-screen flow succeeded end-to-end.
Read the original → docs.flutter.dev
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.