CheckOps home

Tools directory

F

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.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

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

  1. Bundled with Flutter: No extra installation.
  2. Widget tests: Fast UI component tests without a device.
  3. Finders and matchers: Locate widgets and assert on them.
  4. Goldens and coverage: Image comparisons and LCOV output.

Pros

  1. Free: Included with Flutter.
  2. Fast: Widget tests run on the host without devices.

Cons

  1. No native interaction: Widget tests cannot test platform UI; use integration_test or Patrol.
  2. Golden flakiness: Goldens can differ across platforms and fonts.
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).

  1. All Flutter developers for unit and widget tests.
  2. 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.