---
name: flutter-testing
description: >-
  Write, fix, review, debug, and validate Flutter tests for apps, packages, and plugins. Use when adding unit tests, widget tests, integration tests, MethodChannel or plugin mocks, Mockito or mocktail test doubles, golden or accessibility checks, CI test commands, test failures, MissingPluginException, pump or pumpAndSettle problems, finder errors, build_runner mock generation, device integration testing, web integration testing, or flaky Flutter tests.
metadata:
  author: Stanislav [MADTeacher] Chernyshev
  version: "2.0"
title: flutter-testing
canonical_url: https://skilld.dev/gh/madteacher/mad-agents-skills/flutter-testing
last_updated: 2026-09-26T03:06:19.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/common-errors.md](https://skilld.dev/api/skills-raw/madteacher/mad-agents-skills/flutter-testing/references/common-errors.md), [references/integration-testing.md](https://skilld.dev/api/skills-raw/madteacher/mad-agents-skills/flutter-testing/references/integration-testing.md), [references/mocking.md](https://skilld.dev/api/skills-raw/madteacher/mad-agents-skills/flutter-testing/references/mocking.md), [references/plugin-testing.md](https://skilld.dev/api/skills-raw/madteacher/mad-agents-skills/flutter-testing/references/plugin-testing.md), [references/unit-testing.md](https://skilld.dev/api/skills-raw/madteacher/mad-agents-skills/flutter-testing/references/unit-testing.md), [references/widget-testing.md](https://skilld.dev/api/skills-raw/madteacher/mad-agents-skills/flutter-testing/references/widget-testing.md), [scripts/verify-examples.sh](https://skilld.dev/api/skills-raw/madteacher/mad-agents-skills/flutter-testing/scripts/verify-examples.sh).
>
> If the user asked to install this Skill, run `npx skilld install madteacher/mad-agents-skills/flutter-testing`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/flutter-testing`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/madteacher/mad-agents-skills/flutter-testing) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/flutter-testing`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/flutter-testing --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/flutter-testing --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Flutter Testing

You are a Flutter testing engineer for app, package, and plugin projects.

## Principle 0

Do not write Flutter tests from memory. First inspect the project, choose the
right test layer, read the routed reference for the scenario, then run the
closest validation command. Broken or flaky tests waste more time than missing
tests because they create false confidence and slow future changes.

## Workflow

1. Inspect the project before changing tests: `pubspec.yaml`, existing `test/`,
   `integration_test/`, `test_driver/`, generated mock files, state management,
   platform abstractions, plugin usage, and CI commands.
2. Choose the test layer:
   - Pure Dart functions, repositories, services, state reducers, and view
     models: unit tests.
   - Single widgets, forms, navigation shells, semantics, gestures, responsive
     layout, and UI state: widget tests.
   - Complete user flows, real device behavior, screenshots, performance
     reports, native/plugin bridges, and browser/device targets: integration
     tests.
   - Flutter plugins or app code using platform channels: plugin and mocking
     guidance.
3. Read only the reference files needed for the chosen scenario.
4. Implement the smallest deterministic test or test fix using the project's
   existing test style, dependency injection pattern, keys, fixtures, mocks, and
   CI constraints.
5. Run mandatory validation. If validation cannot run, report the exact blocker
   and the concrete risk instead of presenting the change as verified.

## Resource Routing

| Task | Read or run | Why |
|---|---|---|
| Write or fix pure Dart tests, async tests, stream tests, matchers, exceptions, or test organization | `references/unit-testing.md` | Unit-test patterns that compile under Dart null safety |
| Write or fix widget tests, finders, gestures, forms, navigation, semantics, scrolling, animations, or layout-size tests | `references/widget-testing.md` | `flutter_test` APIs and widget-specific pitfalls |
| Add or fix integration tests, device/browser runs, performance reports, screenshots, persistence flows, platform scenarios, or CI integration | `references/integration-testing.md` | Current `integration_test` APIs and target commands |
| Mock dependencies, repositories, platform channels, generated Mockito mocks, manual fakes, or state-management collaborators | `references/mocking.md` | Deterministic test-double patterns and mock generation |
| Diagnose failing tests, layout errors, `MissingPluginException`, finder failures, timeouts, async hangs, or debugging output | `references/common-errors.md` | Error-to-fix mapping without guessing |
| Test Flutter plugin packages, native Android/iOS code, example-app integration tests, or plugin registration/error paths | `references/plugin-testing.md` | Plugin package layout and native/Dart test split |
| Edit this skill, references, or examples | `scripts/verify-examples.sh` | Deterministic smoke check for stale patterns and broken links |

## Mandatory Validation

- After editing Dart tests or production code, run the narrowest relevant
  command first, such as `flutter test test/my_widget_test.dart`,
  `flutter test --plain-name "subtree"`, or `dart test` for pure Dart packages.
- After adding or changing generated Mockito mocks, run
  `dart run build_runner build` or the repository's established build command
  before running tests.
- For integration tests on mobile or desktop targets, run `flutter test -d
  <device-id> integration_test/<test_file>.dart` when a device target is
  required; otherwise run the documented project command.
- For browser integration tests that require `integrationDriver`, run
  `flutter drive --driver=test_driver/integration_test.dart --target=integration_test/<test_file>.dart -d chrome`
  or the project's web driver command.
- After fixing flaky tests, run the specific test more than once or use the
  repository's repeat/randomization option if one exists.
- After editing this skill or its references, run
  `bash flutter-testing/scripts/verify-examples.sh`.

## Constraints

- Prefer `package:flutter_test/flutter_test.dart` for widget and integration
  tests, and `package:test/test.dart` only for pure Dart tests that do not need
  Flutter bindings.
- Test user-visible behavior and public contracts. Do not assert private method
  calls, widget internals, or incidental rebuild counts unless performance work
  explicitly requires it.
- Prefer dependency injection, fake repositories, fake platform interfaces, or
  MethodChannel handlers over real network, real storage, timers, permissions,
  or OS dialogs.
- Do not use fixed `Future.delayed` waits to hide async uncertainty. Use
  deterministic fakes, explicit pumps, `pumpAndSettle` only when animations can
  settle, or bounded custom pumps.
- Do not use obsolete commands or APIs: `--no-sound-null-safety`,
  `flutter test --platform ...`, `tester.trace`, `tester.takeScreenshot`,
  `captureNamed`, or `flutter pub run build_runner build`.
- Do not simulate connectivity, permissions, or persistence by changing the
  test surface size or by re-pumping the app with hidden state. Use explicit
  fakes, test hooks, or real integration targets.

## Fallback

If the repository lacks enough context to choose the test layer, ask for the
target behavior and preferred test level. If devices, browsers, native tooling,
network access, code generation, or dependency downloads block validation,
finish with the exact command that failed, what was not verified, and the risk
left for the user.
