iamantoniodinuzzo/claude-flutter/generate-widget-tests

Claude Code and agent skill by iamantoniodinuzzo/claude-flutter

Trust tier 3
  • community
Source check pending

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-tests

SKILL.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:

InputMode
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.

List all .dart files (excluding .g.dart and *_test.dart)
in apps/pollicino_viewer/lib/src/features/<name>/presentation/.
For each file read only the first 30 lines and report:
- Widget class name and superclass (StatelessWidget, StatefulWidget, ConsumerWidget, ConsumerStatefulWidget)
- Presence of existing `static const *Key` fields
- Approximate file line count
Step F2 — Classify each widget
TierCriteriaAction
A — Test nowScreen (*_screen.dart), Dialog with state, ConsumerStateful*, widget > 150 lines with Keys or user interactionsWrite full Robot test
B — Test nowNon-screen ConsumerWidget or StatefulWidget, widget with form/validation, complex conditional UIWrite focused Robot test
C — SkipPure stateless display widget < 80 lines, no providers, no interactions, no navigationSkip (return to user with note)

Output a test plan table to the user before writing any code:

| File | Class | Tier | Reason |
|------|-------|------|--------|
| sign_in_screen.dart | SignInScreen | A | ConsumerStatefulWidget, full form, navigation |
| booking_calendar.dart | BookingCalendar | A | 215 lines, ConsumerWidget, state interactions |
| booking_cancel_confirm_dialog.dart | BookingCancelConfirmDialog | B | Dialog with actions |
| booking_day_list.dart | BookingDayList | C | Stateless display list, 126 lines, no interactions |
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.dart once
  • 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:

Agent 1: sign_in_screen.dart → full Robot test
Agent 2: booking_calendar.dart → full Robot test
Agent 3: booking_cancel_confirm_dialog.dart + booking_day_list.dart → focused tests

Each agent receives:

  1. The full path of its target widget file(s)
  2. The list of already-identified mocks (to avoid duplication)
  3. Instructions from this skill's phases (Phase 0 through Phase 11)
Step F5 — After all agents complete
  1. Check that no two agents declared the same mock class.
  2. If duplicates found → move to test/src/mocks.dart, update imports.
  3. Run flutter test to 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:

PatternFile
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.

  1. Read the widget source — list every interactive element, key, state change, and navigation action.
  2. Read the existing test file — extract group(...) and testWidgets(...) names, plus the Robot class.
  3. Diff — identify missing coverage: untested user flows, missing assertions for states (loading, error, empty), unexercised navigation.
  4. Append — add missing group blocks at the end of main(). 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:

  1. The target widget file — understand every Key, interactive element, conditional UI, navigation, async state.
  2. The widget's dependencies — controllers, services, providers it consumes via ref.watch / ref.read.
  3. The app's central mocks file — reuse existing mocks:
  • pollicino_viewer: apps/pollicino_viewer/test/src/mocks.dart
  • tomcat_portal: apps/tomcat_portal/test/src/mocks.dart
  1. Sibling test files — scan for existing Robots that can be composed (child robots).
Rule — no duplicate mocks: never declare class 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
dart
static const rootKey = Key('widgetName_root');
static const emailFieldKey = Key('widgetName_emailField');
static const submitButtonKey = Key('widgetName_submitButton');
static const loadingIndicatorKey = Key('widgetName_loadingIndicator');

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.

dart
class MyScreen extends ConsumerStatefulWidget {
const MyScreen({super.key});
// Widget keys for testing
static const rootKey = Key('myScreen_root');
static const titleKey = Key('myScreen_title');
static const submitButtonKey = Key('myScreen_submitButton');
@override
ConsumerState<MyScreen> createState() => _MyScreenState();
}
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:

dart
// ❌ WRONG — _MyDialog.titleKey is inaccessible from the test file
class _MyDialog extends StatefulWidget {
static const titleKey = Key('myDialog_title');
}
// ✅ CORRECT — top-level, importable from any test file
const myDialogTitleKey = Key('myDialog_title');
const myDialogSaveButtonKey = Key('myDialog_saveButton');
const myDialogCancelButtonKey = Key('myDialog_cancelButton');
class _MyDialog extends StatefulWidget { ... }

Phase 3 — Robot Class Structure

A Robot encapsulates all interaction with a single widget/screen. It has four sections:

dart
class MyScreenRobot {
MyScreenRobot(this.tester);
final WidgetTester tester;
// ==================== CHILD ROBOTS ====================
// Compose robots for nested reusable widgets
late final childWidgetRobot = ChildWidgetRobot(tester);
// ==================== FINDERS (Private) ====================
// ALWAYS use Key-based finders. NEVER use find.text() or find.byTooltip().
Finder _findRoot() => find.byKey(MyScreen.rootKey);
Finder _findSubmitButton() => find.byKey(MyScreen.submitButtonKey);
// ==================== ACTIONS (Public) ====================
// Each action simulates a single user gesture.
Future<void> tapSubmitButton() async {
await tester.ensureVisible(_findSubmitButton());
await tester.tap(_findSubmitButton());
await tester.pump();
}
// ==================== WORKFLOWS (Public) ====================
// Compose multiple actions into common user flows.
Future<void> submitForm({required String email, required String password}) async {
await enterEmail(email);
await enterPassword(password);
await tapSubmitButton();
}
// ==================== ASSERTIONS (Public) ====================
// Each assertion checks one thing.
void expectScreenVisible() {
expect(_findRoot(), findsOneWidget);
}
}
Rules
  1. Finders are always private — prefixed with _find. Tests never call finders directly.
  2. Finders use only Keys — find.byKey(WidgetClass.someKey). Never find.text(...), find.byTooltip(...), or hardcoded strings.
  3. Actions are `Future<void>` — they await tester.ensureVisible, perform the gesture, then pump.
  4. Workflows combine actions — for common multi-step flows (fill form + submit).
  5. Assertions are `void` — synchronous, each checks one expectation.
  6. Typed widget access — to assert widget properties (enabled, obscured), use tester.widget<T>(finder):
dart
void expectSubmitButtonEnabled(bool enabled) {
final button = tester.widget<FilledButton>(_findSubmitButton());
expect(button.enabled, enabled);
}
void expectPasswordObscured(bool obscured) {
final editableText = tester.widget<EditableText>(
find.descendant(
of: _findPasswordField(),
matching: find.byType(EditableText),
),
);
expect(editableText.obscureText, obscured);
}
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.

dart
class PhoneNumberFieldRobot {
PhoneNumberFieldRobot(this.tester);
final WidgetTester tester;
Finder _findTextField() => find.byKey(PhoneNumberField.textFieldKey);
Future<void> enterPhoneNumber(String number) async {
await tester.ensureVisible(_findTextField());
await tester.enterText(_findTextField(), number);
await tester.pump();
}
void expectPhoneFieldVisible() {
expect(_findTextField(), findsOneWidget);
}
}
class RegistrationScreenRobot {
RegistrationScreenRobot(this.tester);
final WidgetTester tester;
late final phoneRobot = PhoneNumberFieldRobot(tester);
// ... parent robot methods ...
}
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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/iamantoniodinuzzo/claude-flutter/generate-widget-tests/badge)](https://verified-skill.com/skills/iamantoniodinuzzo/claude-flutter/generate-widget-tests)

Something wrong with this skill or its page? Tell us.