flutter-testing
madteacher/mad-agents-skills
Write, fix, and debug Flutter tests across unit, widget, integration, and plugin layers.
What is flutter-testing?
A Flutter testing engineer skill for app, package, and plugin projects. Use it to write or fix unit tests, widget tests, integration tests, mocks, golden checks, and diagnose test failures—always validating with the narrowest relevant command first.
- Inspect projects and choose the right test layer (unit, widget, integration, or plugin)
- Write and fix pure Dart unit tests, async tests, stream tests, and matchers
- Create widget tests for UI, forms, navigation, gestures, semantics, and layout
- Build integration tests for complete user flows, device behavior, and platform channels
- Mock dependencies, repositories, platform channels, and generated Mockito mocks
- Diagnose and fix failing tests, MissingPluginException, finder errors, timeouts, and flaky tests
How to install flutter-testing
npx skills add https://github.com/madteacher/mad-agents-skills --skill flutter-testing- Flutter SDK installed
- Existing Flutter project with pubspec.yaml
- Test dependencies (flutter_test, test, mockito, or mocktail as needed)
How to use flutter-testing
- 1.Inspect the project structure: pubspec.yaml, test/, integration_test/, and existing test patterns
- 2.Choose the test layer based on what you're testing (unit, widget, integration, or plugin)
- 3.Read the appropriate reference guide for your scenario (unit-testing, widget-testing, integration-testing, mocking, or common-errors)
- 4.Implement the test using the project's existing style, dependency injection, and fixtures
- 5.Run the narrowest validation command: flutter test <file>, dart test, or flutter test -d <device> integration_test/<file>
- 6.For generated mocks, run dart run build_runner build before testing
- 7.Repeat flaky tests or use the repository's randomization option to verify stability
Use cases
- Adding unit tests for business logic, repositories, and state management
- Writing widget tests for forms, navigation, and responsive layouts
- Creating integration tests for end-to-end user flows and device behavior
- Mocking platform channels and native code for plugin testing
- Fixing test failures, async hangs, and layout errors in existing tests
- Flutter app developers writing tests
- Package and plugin maintainers
- QA engineers validating Flutter behavior
- Teams implementing CI test pipelines
flutter-testing FAQ
Use unit tests for pure Dart functions, repositories, and services. Use widget tests for single widgets, forms, and UI state. Use integration tests for complete user flows, real device behavior, and platform channel interactions.
Read references/mocking.md for MethodChannel handlers and fake platform interfaces. For Mockito-generated mocks, run dart run build_runner build before testing.
Avoid fixed Future.delayed waits. Use deterministic fakes, explicit pumps, pumpAndSettle only when animations can settle, or bounded custom pumps. Repeat the test multiple times to verify stability.
Run the narrowest relevant command first: flutter test test/my_widget_test.dart, flutter test --plain-name "pattern", or dart test for pure Dart. For integration tests on devices, use flutter test -d <device-id> integration_test/<file>.dart.
This error occurs when a platform channel is not properly mocked or the plugin is not registered. Read references/common-errors.md for error-to-fix mapping, or use fake platform interfaces and MethodChannel handlers in tests.
Full instructions (SKILL.md)
Source of truth, from madteacher/mad-agents-skills.
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"
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
- Inspect the project before changing tests:
pubspec.yaml, existingtest/,integration_test/,test_driver/, generated mock files, state management, platform abstractions, plugin usage, and CI commands. - 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.
- Read only the reference files needed for the chosen scenario.
- Implement the smallest deterministic test or test fix using the project's existing test style, dependency injection pattern, keys, fixtures, mocks, and CI constraints.
- 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", ordart testfor pure Dart packages. - After adding or changing generated Mockito mocks, run
dart run build_runner buildor 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>.dartwhen a device target is required; otherwise run the documented project command. - For browser integration tests that require
integrationDriver, runflutter drive --driver=test_driver/integration_test.dart --target=integration_test/<test_file>.dart -d chromeor 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.dartfor widget and integration tests, andpackage:test/test.dartonly 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.delayedwaits to hide async uncertainty. Use deterministic fakes, explicit pumps,pumpAndSettleonly 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, orflutter 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.
Related skills
More from madteacher/mad-agents-skills and the wider catalog.

flutter-adaptive-ui
Build responsive Flutter UIs that adapt to any screen size, input method, and platform without device detection.

flutter-animations
Add, fix, refactor, debug, test, and explain Flutter animations and motion effects.

flutter-architecture
Design, refactor, and review Flutter app architecture with MVVM, layered boundaries, and scalable project structure.

flutter-networking
>-

frontend-design
Generate and guide UI development with concept-led design spanning editorial warmth, bright product design, and high-contrast neon systems.

magicpath
Find, preview, inspect, install, export, and edit UI components via MagicPath CLI.