D
TestingBeginner10 XP2 min read

What are the three types of tests in Flutter?

TL;DR: Flutter has unit tests (pure Dart logic, no UI), widget tests (render a single widget in a test environment), and integration tests (full app on a real or simulated device via flutter_test / integration_test).

Full Answer

AspectUnitWidget
ScopeFunctions, classes, logicSingle widget or small tree
SpeedMillisecondsSeconds
DependenciesMocked or realFlutter test environment (no real device)
Packagetestflutter_test

Integration Tests

Integration tests run the full app and interact with it like a user. They use the integration_test package, run on a device/emulator, and are the slowest but most realistic.

🎯

Follow the testing pyramid: many unit tests, fewer widget tests, even fewer integration tests. Unit and widget tests should cover 80%+ of your codebase.

Code Examples

dartAll three test types
Output
// Unit: passes in ms
// Widget: passes in ~1s
// Integration: passes in ~10s on device

Common Mistakes

  • Skipping widget tests and going straight to integration tests — much harder to debug
  • Testing implementation details instead of behavior (e.g., testing private methods)

Interview Tip

💡

Show you understand the cost/confidence trade-off. Unit tests are cheap but don't test rendering; integration tests are expensive but test the full app.

#unit-test#widget-test#integration-test#testing-pyramid