Flutter Testing Complete Guide — Widget & Integration Tests for Quality Assurance
Quality matters even in indie development. This guide covers the three-layer testing approach — Unit, Widget, and Integration — to keep your Flutter app reliable.
The Three Testing Layers
Type Speed Confidence Best For
Unit ⚡ Fastest Logic only Business logic, calculations
Widget 🚀 Fast UI + Logic Widget rendering, user interaction
Integration 🐢 Slow Near-real Screen flows, APIs, full journeys
Setup
dev_dependencies : flutter_test : sdk : flutter integration_test : sdk : flutter mockito : ^5.4.4 build_runner : ^2.4.9
Enter fullscreen mode
Exit fullscreen mode
Unit Tests
// test/unit/score_calculator_test.dart import 'package:flutter_test/flutter_test.dart' ; import 'package:my_app/services/score_calculator.dart' ;
void main () { group ( 'ScoreCalculator' , () { late ScoreCalculator calculator ; setUp (() = > calculator = ScoreCalculator ());
test ( 'popularity bonus: rank 1 returns +0.05' , () { expect (…