CheckOps
Flutter Test (flutter_test)
flutter_test is Flutter's official testing package and flutter test command for unit and widget tests, with WidgetTester, finders, matchers, golden-file tests and coverage.
- Unit Testing
- Dart
- Mobile
- Open source
- Free
- Test Runner
- Unit testing
- End-to-end & functional
- Integration testing
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
Introduction
Flutter’s testing overview describes three categories of automated tests: unit tests for a single function, method or class; widget tests (component tests) for a single widget; and integration tests for a complete app or a large part of it. The flutter_test package, bundled with the Flutter SDK, supports the first two, and flutter test runs them on the host machine without a device or emulator.
Unit tests use the Dart test API (test, group, expect). Widget tests use testWidgets, which provides a WidgetTester to build widgets (pumpWidget), trigger frames (pump, pumpAndSettle), and interact (tap, enterText, drag). Finders (find.text, find.byKey, find.byType) locate widgets and matchers (findsOneWidget, findsNothing) assert on them. Golden-file tests compare rendered widgets with reference images using matchesGoldenFile, and flutter test --coverage produces LCOV coverage. The overview explains the trade-offs: widget tests are fast and give good confidence, while integration tests (with integration_test) run on real devices for the highest fidelity.
Features
- Bundled with Flutter: No extra installation.
- Widget tests: Fast UI component tests without a device.
- Finders and matchers: Locate widgets and assert on them.
- Goldens and coverage: Image comparisons and LCOV output.
Pros
- Free: Included with Flutter.
- Fast: Widget tests run on the host without devices.
Cons
- No native interaction: Widget tests cannot test platform UI; use integration_test or Patrol.
- Golden flakiness: Goldens can differ across platforms and fonts.
Usage and Links (Example)
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:my_app/counter.dart';
void main() {
testWidgets('increments counter', (tester) async {
await tester.pumpWidget(const MaterialApp(home: Counter()));
expect(find.text('0'), findsOneWidget);
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
expect(find.text('1'), findsOneWidget);
});
}
flutter test --coverage
Resources:
Pricing
Free and open source as part of the Flutter SDK (BSD-3-Clause licence).
Recommended for?
- All Flutter developers for unit and widget tests.
- Teams wanting fast UI tests without emulators.
Conclusion
flutter_test is the backbone of Flutter testing, with widget tests offering an excellent balance of speed and confidence.
Alternatives
Other tools on CheckOps that cover similar ground. Open a page, or compare one with Flutter Test (flutter_test) side by side.
FFlutter integration_testintegration_test is Flutter's official package for end-to-end tests that run a full app on physical devices, emulators or Firebase Test Lab, using flutter_test-style APIs and the flutter drive or flutter test commands.Compare with Flutter Test (flutter_test)
PPatrolPatrol is LeanCode's Apache-2.0, Flutter-first E2E UI testing framework that extends integration_test with native automation (permissions, notifications, WebViews, device settings), custom finders, test isolation and sharding.Compare with Flutter Test (flutter_test)
Mmocktailmocktail is an MIT-licensed Dart mocking library, inspired by mockito, with null-safety support and no manual mocks or code generation, widely used in Flutter tests.Compare with Flutter Test (flutter_test)
AAppiumCross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol.Compare with Flutter Test (flutter_test)
MMaestroMaestro is a YAML UI test runner for Android, iOS, and web. The CLI is free and open source; Maestro Cloud is paid.Compare with Flutter Test (flutter_test)- DDetoxGray box end-to-end testing and automation framework for mobile apps.Compare with Flutter Test (flutter_test)