Testing Flutter Apps: Unit, Widget, and Integration

Flutter has three test types that cover different layers. Here's a practical strategy that catches real bugs without over-investing in any single layer.

Richard GamoraRichard GamoraFullstack developer·4 min read
FlutterTesting

Flutter ships with three test types — unit, widget, and integration — and the official docs cover each one. What is harder to find is a strategy for using them together without over-investing. Here is what works for me.

Unit tests for pure logic

Repository functions, parsers, validators, formatters — anything that is plain Dart with no widgets. Unit tests run in milliseconds and are the cheapest layer to maintain. Aim for high coverage here.

Widget tests for component behavior

Widget tests render a single widget and assert on it. Use them for forms, list items, custom controls — anything where the value is the rendered output reacting to input. Widget tests are slower than unit tests but still fast (tens of ms each).

Mock external dependencies (HTTP, plugins) so widget tests do not hit real services. The point is to verify your widget code, not the network.

Integration tests for critical flows

Integration tests run on a real device or emulator and exercise the full app. They are slow (minutes), expensive to maintain, and worth it only for the handful of flows that matter most: login, checkout, the one or two paths through the app you cannot ship a release without.

Treat integration tests as smoke tests, not coverage. Five solid ones beat fifty flaky ones.

What to skip

Do not write widget tests for trivial display widgets — the test ends up duplicating the build method. Do not write integration tests for every feature. Coverage targets that mix the three layers ("95% coverage overall") tend to push teams toward the cheap layer until the metric looks good without actual safety.

About the author

Richard Gamora

Richard Gamora

Fullstack developer based in the Philippines, working mostly with Laravel and Vue.js, with eight years of production experience across web and mobile.

me@richardgamora.comUpwork ↗

More on Flutter