Skip to content
tezvyn:
Menu

Unit, widget, and integration test differences in Flutter

Source: docs.flutter.devEasyHow cards are made

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's really being asked

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.

The mistakes people make

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.

What usually comes next

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.

A 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.

Interview question

You need to verify a button tap updates text on one Flutter screen without launching a device. Which statement about the correct test approach is true?

  • a.It runs the compiled app on an emulator to render the UI
  • b.It uses WidgetTester to pump the screen in a headless environmentCorrect
  • c.It validates the full user journey across multiple screens and platform channels
  • d.It exercises pure Dart logic without rendering any widgets
Why?

Widget tests use WidgetTester to pump widgets into a simulated headless environment, so you can verify UI interactions without a device or emulator. The emulator option is tempting but wrong because running on a real device or emulator defines an integration test, not a widget test.

Just read this? Test yourself on what you have been reading.

Read the original → docs.flutter.dev

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on flutter — each one lists the topics its interview covers.

See open roles