iamantoniodinuzzo/claude-flutter/generate-widget-tests
Claude Code and agent skill by iamantoniodinuzzo/claude-flutter
- community
Checking that the SKILL.md file is still in the repository.
Generate widget tests using the Robot Testing pattern for Flutter screens and widgets. Produces tests that identify widgets exclusively by Key (never by text), support i18n, use Robot classes to separate finders/actions/assertions, and follow GWT structure. Use proactively whenever the user asks to write, generate, add, create, or fix widget tests, screen tests, UI tests, robot tests, or integration-style widget tests for any widget, screen, or dialog in this Flutter project — even if they just say \"write tests for X\" or \"add widget coverage to Y\".
Install
npx vskill@latest install iamantoniodinuzzo/claude-flutter/generate-widget-testsSKILL.md
The same SKILL.md was published earlier as iamantoniodinuzzo/claude-flutter/generate-widget-tests.
Generate Widget Tests — Robot Testing Pattern
Runtime and resources
Use the current agent's native file, search, shell, and question tools; plain-text questions and direct sequential scans are valid fallbacks. Subagents are optional and require host permission. Bundled paths below are relative to this installed skill directory; application paths are relative to the target Flutter project. Resolve sibling skills through the installed skill registry (or sibling directories), never by assuming a skills/ folder in the application. If a required dependency is absent, name it and report the affected step as unavailable; never invent its rules or claim complete coverage.
Entry Point: Single Widget or Entire Folder?
Read the user's request first to determine operating mode:
| Input | Mode | |
|---|---|---|
A specific file (sign_in_screen.dart) | Single-widget mode → skip to Phase 0 | |
A feature folder (features/booking/presentation/) | Folder mode → start at Phase F (below) |
Phase F — Folder Mode: Discovery, Strategy & Parallelization
Step F1 — Discover all widgets in the folder
Use a permitted read-only subagent, otherwise list directly all .dart files recursively in presentation/. Exclude .g.dart and *_test.dart.
Step F2 — Classify each widget
| Tier | Criteria | Action | |
|---|---|---|---|
| A — Test now | Screen (*_screen.dart), Dialog with state, ConsumerStateful*, widget > 150 lines with Keys or user interactions | Write full Robot test | |
| B — Test now | Non-screen ConsumerWidget or StatefulWidget, widget with form/validation, complex conditional UI | Write focused Robot test | |
| C — Skip | Pure stateless display widget < 80 lines, no providers, no interactions, no navigation | Skip (return to user with note) |
Output a test plan table to the user before writing any code:
Step F3 — Identify shared dependencies
Before launching agents, read all Tier A+B widget files fully and identify:
- Common mocks needed (services, controllers, repositories)
- Providers that appear in multiple widgets → add to central
mocks.dartonce - Shared child robots (reusable widget components)
Step F4 — Launch parallel agents
Launch one Agent per Tier A widget, and group Tier B widgets (max 2–3 per agent) to avoid overloading context. Use parallel subagents only when available and permitted; otherwise process the same groups sequentially:
Each agent receives:
- The full path of its target widget file(s)
- The list of already-identified mocks (to avoid duplication)
- Instructions from this skill's phases (Phase 0 through Phase 11)
Step F5 — After all agents complete
- Check that no two agents declared the same mock class.
- If duplicates found → move to
test/src/mocks.dart, update imports. - Run
flutter testto verify everything compiles.
Dependencies
Complex provider scenarios require the installed unit-test skill. Resolve its directory from the registry or ../unit-test/. If absent, report missing patterns without claiming those scenarios are covered.
Pattern References
For complex scenarios, read the relevant pattern file before writing any code:
| Pattern | File | |
|---|---|---|
StreamProvider overrides (AsyncData vs Stream.value) | ../unit-test/patterns/stream-provider-overrides.md | |
Notifier whose build() watches a StreamProvider | ../unit-test/patterns/notifier-with-stream-deps.md | |
Computed provider that returns AsyncValue<T> synchronously | ../unit-test/patterns/computed-async-value-providers.md | |
Fixture helper functions and makeContainer factory | ../unit-test/patterns/fixture-helpers.md | |
| StreamProvider family error / loading state in widget tests | ../unit-test/patterns/stream-provider-overrides.md |
Phase 0 — Gap Detection (existing test file)
If the test file already exists, read it first and compare against the source widget.
- Read the widget source — list every interactive element, key, state change, and navigation action.
- Read the existing test file — extract
group(...)andtestWidgets(...)names, plus the Robot class. - Diff — identify missing coverage: untested user flows, missing assertions for states (loading, error, empty), unexercised navigation.
- Append — add missing
groupblocks at the end ofmain(). Add missing methods to the existing Robot. Never restructure existing tests or robots.
If the test file does not exist, skip to Phase 1.
Phase 1 — Discover Before Writing
Before producing any code, read these in order:
- The target widget file — understand every Key, interactive element, conditional UI, navigation, async state.
- The widget's dependencies — controllers, services, providers it consumes via
ref.watch/ref.read. - The app's central mocks file — reuse existing mocks:
pollicino_viewer:apps/pollicino_viewer/test/src/mocks.darttomcat_portal:apps/tomcat_portal/test/src/mocks.dart
- Sibling test files — scan for existing Robots that can be composed (child robots).
Rule — no duplicate mocks: never declareclass MockFoo extends Mock implements Foo {}if one already exists centrally or in a sibling.
Rule — no mockito: all new test files use mocktail exclusively. Do not copy legacy mockito patterns (.mocks.dart,@GenerateMocks).
Phase 2 — Ensure Keys Exist in the Widget
Before writing the Robot, verify the widget source defines static const Keys for every interactive and assertable element.
Key naming convention
Pattern: Key('<widgetNameCamelCase>_<elementNameCamelCase>').
If Keys are missing
Add them to the widget source as static const fields on the widget class before writing any test code. Group them at the top of the class body, right after the constructor.
Exception: private widget classes
static const fields on a private class (_MyDialog) are not accessible from test files. Declare keys as top-level constants in the same source file:
Phase 3 — Robot Class Structure
A Robot encapsulates all interaction with a single widget/screen. It has four sections:
Rules
- Finders are always private — prefixed with
_find. Tests never call finders directly. - Finders use only Keys —
find.byKey(WidgetClass.someKey). Neverfind.text(...),find.byTooltip(...), or hardcoded strings. - Actions are `Future<void>` — they
await tester.ensureVisible, perform the gesture, then pump. - Workflows combine actions — for common multi-step flows (fill form + submit).
- Assertions are `void` — synchronous, each checks one expectation.
- Typed widget access — to assert widget properties (enabled, obscured), use
tester.widget<T>(finder):
Exception: find.byType() is acceptable
Use find.byType() only for:
- Generic indicators:
CircularProgressIndicator,SnackBar,LinearProgressIndicator - Descendant matching within a Key-scoped parent:
find.descendant(of: keyFinder, matching: find.byType(T))
Never use find.byType() as the primary finder for business widgets.
Phase 4 — Child Robot Composition
When a screen contains reusable child widgets (e.g., a custom PhoneNumberField, a UserTypeSelector), create separate Robot classes for each and compose them.
When to compose
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/generate-widget-tests/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/iamantoniodinuzzo/claude-flutter/generate-widget-tests)