Flutter testing

From HoangNguyen0403/agent-skills-standard · View interactive version

Flutter testing is an AI agent skill from the GitHub repository HoangNguyen0403/agent-skills-standard. Write unit, widget, and integration tests with robot patterns, widget keys, and Patrol in Flutter. Use when implementing test behavior; defer CI-only configuration without test changes.

How to use this skill

Skill file

Flutter Testing Standards

**Priority: P0 (CRITICAL)**

Universal anti-slop rules (naming, identity fixtures, tautologies, skip/focus, mock echoing, bug-first lock, sleeps,

shallow assertions, coverage): anti-slop-rules.md. Only Flutter

deltas follow.

Core Rule Anchors

trees. Ban vacuous expect: () => [isA<BaseState>()] without .having(...) or verify (GUARD-DART-VACUOUS-STATE),

seed echoes (GUARD-DART-SEED-ECHO), duplicate build/seed/act/expect scenarios (GUARD-DART-BLOC-DUPLICATE), and

collaborator mock echoes (GUARD-DART-MOCK-ECHO).

fromJson/toJson or error mapping. Ban tests of generated code and trivial getters/props.

mapping; ban 1:1 pass-through echoing (when(() => dataSource.get()).thenAnswer((_) async => x); expect(await repo.get(), x)).

never prove device layout, native permissions, or deep links; desktop emulation never substitutes native E2E.

Conventions

  1. Test Pyramid: Unit > Widget > Integration; _integration_test.dart only in integration_test/.
  2. AAA: Arrange, Act, Assert in every test.
  3. Builders: Fluent builders when setup repetition obscures intent (OrderBuilder); avoid shared global mocks.
  4. Robot-First: Route all UI interactions and assertions through the Robot pattern (extending BaseRobot), never raw

find.*/expect() in a test body. Use WidgetKeys constants from lib/core/keys/; no inline Key.

  1. Negative Assertions: Add expectXxxNotVisible() in the robot only when absence is part of the business contract.
  2. Widget Testing & Mocking: TestWrapper.init() + tester.pumpLocalizedWidget(...). Register mock BLoCs with GetIt in

setUpAll; stub state and stream in setUp (use whenListen, settle: false for loading states). Prohibit any().

  1. Integration Testing: Use patrolTest with IntegrationAuthHelper.loginOrSkip($) for auth and native interactions

($.native.*) for permissions, alerts, and lifecycle. For permission flows, assert the dialog

(isPermissionDialogVisible) before granting or denying, and assert granted and denied outcomes as separate tests.

Anti-Patterns

Verification

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.