skills/flutter/flutter-testing/SKILL.md
Define testing strategy, test pyramid, and pattern-based conventions (Golden Variants, State Matrix, Interaction Contracts). Use when establishing test architecture or choosing the right testing approach for a Flutter project.
npx skillsauth add dhruvanbhalara/skills flutter-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
lib/ directory structure and end with _test.dart.domain and bloc layers.| Type | Scope | Speed | Skill |
|---|---|---|---|
| Unit | Single function/class | Fast | dart-testing |
| Widget | Single UI component | Medium | flutter-add-widget-test |
| Integration | Full app / user flow | Slow | flutter-add-integration-test |
These three patterns cut repetitive test setup, cover all visual states, and keep widget behavior consistent. They're conventions, not packages.
When a widget has multiple visual states (primary, disabled, hover, error), test all variants in a single structured group() with a Map<String, Widget Function()>:
variants map where keys are state names and values are widget builders.pumpWidget call per variant).goldens/<component>.<variant>.png.surfaceSize via tester.view.physicalSize to avoid flaky pixel diffs.Every stateful widget MUST be tested against ALL possible UI states. Use a state matrix to separate setup from verification:
states map with every state the widget can render (loading, error, data, empty).verify(stateName) callback that asserts correct rendering per state using switch expressions.Reusable widgets have implicit behavioral rules. Define these as explicit, reusable contracts:
test/utils/ for common contracts:
verifyTappable(tester, finder, mockCallback) — Tap fires callback exactly once.verifyDisabledNotTappable(tester, finder, mockCallback) — Tap does NOT fire callback when disabled.verifyValidatesOnBlur(tester, finder) — Validation triggers when focus leaves.group('$ClassName', not group('ClassName',. This ensures consistency and enables better tooling support.group() to organize tests by feature, class, or state for clearer reporting.A RenderFlex overflowed... — Wrap widget in Expanded or constrain dimensions in testVertical viewport was given unbounded height — Wrap ListView in SizedBox with fixed height in testsetState called during build — Defer state changes to post-frame callbackNo MediaQuery widget ancestor — Always wrap test widget in MaterialAppflutter test — Run all unit and widget testsflutter test test/path/to/file_test.dart — Run specific test fileflutter test integration_test/ — Run integration testsflutter test --coverage — Run with coverage reportdart test — Pure Dart unit testsdevelopment
Perform REST API networking operations (GET, POST, PUT, DELETE) using the lightweight and robust standard `http` package, including platform configurations and background parsing models.
development
Configure internationalization and localization support using Flutter's built-in l10n system, App Resource Bundle (ARB) files, and ICU formatting syntax.
development
Create model classes with fromJson/toJson using dart:convert and Dart 3 pattern matching. Use when manually mapping JSON to classes, parsing HTTP responses, or choosing between manual and code-generated serialization.
data-ai
Diagnose and fix Flutter layout constraint violations (RenderFlex overflow, unbounded height/width, ParentData misuse). Use when encountering layout exceptions, yellow-black overflow stripes, or red error screens.