Write many unit tests, a fair number of widget tests, and a few integration tests. A unit test checks one function, a widget test checks one screen without a device, and an integration test taps through the real app. Run the first two with flutter test, which takes seconds.
This guide is for developers with a first working Flutter app who have never tested it. It follows Flutter's testing overview as of Flutter 3.47 (October 2026).
In short:
- Unit tests are fast and cheap but give the lowest confidence.
- Widget tests are quick and catch many UI bugs.
- Integration tests give the highest confidence but are slow and costly to maintain.
- Fake the backend, so tests never need a network.
Unit tests check logic
A unit test calls one function and checks the result. Take the email check from our forms guide:
import 'package:flutter_test/flutter_test.dart';
void main() {
test('rejects an address without @', () {
expect(validateEmail('ada.example.com'), isNotNull);
});
test('accepts a normal address', () {
expect(validateEmail('ada@example.com'), isNull);
});
}
Put files in test/ and end their names with _test.dart. Run all tests with flutter test. Logic that lives in plain Dart classes, not inside widgets, is the easiest to test.
Widget tests check one screen
A widget test builds a widget in a fake environment and lets you tap and look. Flutter's widget testing recipe gives the pattern: build, find, check.
testWidgets('counter goes up when tapped', (tester) async {
await tester.pumpWidget(const MaterialApp(home: CounterPage()));
expect(find.text('0'), findsOneWidget);
await tester.tap(find.byIcon(Icons.add));
await tester.pump(); // rebuild after the tap
expect(find.text('1'), findsOneWidget);
});
WidgetTester drives the widget, and find locates things by text, icon, type or Key. Use pump() to render one frame and pumpAndSettle() to wait for animations to finish. If a screen loads data, replace the data source with a fake instead of calling the network.
Integration tests run the real app
An integration test launches your whole app on a device or emulator. Add the SDK package with flutter pub add "dev:integration_test:{sdk: flutter}", then put tests in integration_test/.
Flutter's integration testing guide documents flutter test integration_test/app_test.dart for a connected device and flutter drive for the web. Write only a handful, for journeys that must never break: sign up, create an item, check out.
Fake the backend, not the widget
Tests should not need the internet. Pass fakes in through the constructor or, with Riverpod, through ProviderScope(overrides: [...]).
For packages, mocktail makes mock classes without code generation. For Firebase, fake_cloud_firestore and firebase_auth_mocks give in-memory versions.
Here is the pattern with Riverpod. The screen reads a repository through a provider, and the test replaces that provider with a fake that returns fixed data.
final ordersRepositoryProvider =
Provider<OrdersRepository>((ref) => HttpOrdersRepository());
testWidgets('shows orders from a fake repository', (tester) async {
await tester.pumpWidget(ProviderScope(
overrides: [
ordersRepositoryProvider.overrideWithValue(FakeOrdersRepository()),
],
child: const MaterialApp(home: OrdersScreen()),
));
await tester.pumpAndSettle(); // wait for the async load
expect(find.text('Order 1042'), findsOneWidget);
});
No network call happens, so the test is fast and gives the same result every time. If you use another package, the idea is the same: pass the dependency in, then pass a fake in tests.
GrowApps templates fake Firebase in tests
The GrowApps project template lists flutter_test, fake_cloud_firestore and firebase_auth_mocks as dev dependencies. It also ships a firebase_test_helpers.dart file with a pumpTestApp() helper.
It wraps a widget in a ProviderScope whose overrides replace Firebase Auth and Firestore with in-memory fakes. Without that, a widget test fails with "No Firebase App has been created", because main() never runs under flutter test. See GrowApps.
Add one test now
Pick your riskiest pure function, such as a price calculation, and write two test() cases: one normal, one edge. Run flutter test. Next, read how to choose state management that is easy to fake in tests.