skills/flutter-widget-testing/SKILL.md
Widget and component testing for Flutter: pumping widgets, finders, matchers, interaction simulation, golden tests, and accessibility checks. Trigger: When writing widget tests, testing UI components, creating golden tests, or verifying accessibility in Flutter.
npx skillsauth add 333-333-333/agents flutter-widget-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.
| Pattern | Rule |
|---------|------|
| Test FIRST | Write the failing widget test before the widget. Red -> Green -> Refactor. |
| Wrap with app shell | Always wrap tested widgets in MaterialApp or the Forui theme equivalent |
| pump vs pumpAndSettle | pump() advances one frame; pumpAndSettle() waits for all animations |
| Finders are lazy | find.text('X') doesn't search until used in expect() or tester.tap() |
| Golden tests pinned | Update goldens explicitly with --update-goldens; never auto-update in CI |
| Test behavior, not pixels | Prefer semantic finders (find.text, find.byType) over pixel coordinates |
| Riverpod: use ProviderScope | Wrap widget in ProviderScope with overrides for test isolation |
mobile/
test/
shared/
presentation/
atoms/
app_button_test.dart
app_text_field_test.dart
app_badge_test.dart
molecules/
emphasis_headline_test.dart
organisms/
pet_emoji_carousel_test.dart
features/
auth/
presentation/
pages/
welcome_page_test.dart
widgets/
auth_sheet_test.dart
goldens/ # Golden reference images
shared/
atoms/
app_button_light.png
app_button_dark.png
features/
auth/
welcome_page_light.png
helpers/
pump_app.dart # Shared widget wrapper helper
test_theme.dart # Theme setup for tests
Every widget test needs a proper app shell with theme. Create a shared helper:
See assets/pump_app.dart
See assets/app_button_test.dart
See assets/app_text_field_test.dart
See assets/interaction_tests.dart
See assets/welcome_page_test.dart
See assets/navigation_test.dart
See assets/golden_test.dart
See assets/accessibility_test.dart
| Finder | Use For |
|--------|---------|
| find.text('X') | Find widget displaying exact text |
| find.textContaining('X') | Find widget containing text |
| find.byType(AppButton) | Find widget by runtime type |
| find.byKey(Key('x')) | Find widget by key |
| find.byIcon(Icons.home) | Find widget by icon |
| find.descendant(of: x, matching: y) | Find widget nested inside another |
| find.ancestor(of: x, matching: y) | Find parent widget |
| find.byWidgetPredicate((w) => ...) | Custom predicate |
| find.bySemanticsLabel('X') | Find by accessibility label |
| Matcher | Verifies |
|---------|----------|
| findsOneWidget | Exactly one match |
| findsNothing | No matches |
| findsNWidgets(n) | Exactly N matches |
| findsAtLeastNWidgets(n) | At least N matches |
| matchesGoldenFile('path') | Visual match against golden |
# Run all widget tests
flutter test
# Run specific widget test
flutter test test/shared/presentation/atoms/app_button_test.dart
# Update golden files (run locally, commit the PNGs)
flutter test --update-goldens
# Update specific golden
flutter test --update-goldens test/shared/presentation/atoms/app_button_golden_test.dart
# Run with coverage
flutter test --coverage
# Run tests matching name
flutter test --name "AppButton"
See assets/pubspec_dev_deps.yaml
| Don't | Do |
|-------|-----|
| Test without app shell/theme | Always use pumpApp() helper with Forui theme |
| Use find.byType(Text) broadly | Use find.text('specific text') for precision |
| Forget pump() after interactions | Always pump() or pumpAndSettle() after tap/input |
| Hardcode pixel positions | Use semantic finders |
| Update goldens in CI | Only update locally, review diffs, commit PNGs |
| Test Forui internals | Test YOUR widget's behavior, not Forui's |
| Skip dark mode tests | Test both light and dark themes |
| Forget to dispose controllers | Use addTeardown or dispose in tearDown |
testing
Review Flutter components and screens for UX/UI compliance. Trigger: When user invokes /ux-review command or requests UX audit.
development
TypeScript strict patterns and best practices. Trigger: When implementing or refactoring TypeScript in .ts/.tsx (types, interfaces, generics, const maps, type guards, removing any, tightening unknown).
testing
Testing philosophy and strategy for every feature: test pyramid, mandatory levels per change type, completion checklist, and skill delegation. Trigger: When planning tests for a feature, reviewing test coverage, defining acceptance criteria, or asking what tests a change needs.
development
Terraform security practices: sensitive variables, secret management, state protection, .gitignore patterns, and CI/CD credential handling. Trigger: When handling secrets in Terraform, configuring state backends, reviewing .gitignore for Terraform, or setting up CI/CD pipelines for infrastructure.