tezvyn:

Unit, widget, and integration test differences in Flutter

AI-drafted, machine-checkedSource: docs.flutter.devbeginner

Tests your grasp of Flutter's test pyramid and isolation levels. Unit tests check pure Dart logic; widget tests verify UI in a headless environment; integration tests exercise the full app on a device. Red flag: saying widget tests require an emulator.

WHAT THIS TESTS: This question checks whether you understand the boundaries and responsibilities of Flutter's three testing tiers. A senior candidate should know not just the names but the isolation guarantees, execution environment, and speed trade-offs of each layer.

A GOOD ANSWER COVERS four things in order. First, unit tests exercise pure Dart code such as utilities, validators, or view-models without rendering any UI; they run in the Dart VM and complete in milliseconds. Second, widget tests verify the UI layer by pumping widgets into a simulated headless environment using WidgetTester; they test layout, state changes, and user gestures without requiring a device or emulator. Third, integration tests run the compiled app on a real device or emulator and exercise complete user journeys across multiple screens; they validate actual platform channels, navigation, and backend integration. Fourth, the answer should mention the speed and cost pyramid: unit tests are fastest and most numerous, widget tests are in the middle, and integration tests are slowest and fewest.

COMMON WRONG ANSWERS: Candidates often blur widget and integration tests by saying widget tests need a device or emulator. Another red flag is claiming unit tests can verify UI appearance or that integration tests are just large widget tests. Some candidates also forget to mention that widget tests run headless or that integration tests exercise platform plugins and real async boundaries.

LIKELY FOLLOW-UPS: An interviewer might ask when to mock dependencies versus use real services, how to handle asynchronous operations in widget tests, or how to structure tests for state management solutions like BLoC or Riverpod. They may also ask about golden tests as a follow-up to widget testing or CI strategies for running integration tests on Firebase Test Lab.

ONE CONCRETE EXAMPLE: Suppose you are building an e-commerce checkout flow. A unit test would verify that a price calculator correctly applies a 20 percent discount to a cart totaling 100 dollars and returns 80. A widget test would pump the checkout screen, enter a promo code into a text field, tap the apply button, and expect the displayed total to read 80 dollars. An integration test would launch the app, log in as a user, add an item to the cart, navigate to checkout, enter a real credit card via the platform channel, and confirm the order confirmation screen appears.

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.