/qa-mobile:flutter-testingfrom qa-mobile
Guides Flutter testing across unit, widget, and integration layers using flutter_test, mockito, and build_runner. Covers test structure, mocking, coverage, and CI integration.
Ships in qa-mobile. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Per flutter-testing-doc:
"Flutter uses a testing pyramid approach with three main categories":
- Unit Tests - single function / method / class; mocked dependencies; quick.
- Widget Tests - single widget; UI + lifecycle + interactions; quick.
- Integration Tests - full app or large sections; on real devices/emulators; highest confidence; slowest.
The framework ships first-party tooling for all three layers.
Flutter ships with flutter_test (in the SDK). For mocks:
# pubspec.yaml
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
mockito: ^5.4.4
build_runner: ^2.4.13
Pure-Dart functions with mocked dependencies:
// test/cart_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'package:my_app/cart.dart';
void main() {
group('Cart', () {
test('addItem increments count', () {
final cart = Cart();
cart.addItem(Item(sku: 'BOOK-001', qty: 1));
expect(cart.itemCount, 1);
});
test('addItem rejects negative qty', () {
final cart = Cart();
expect(
() => cart.addItem(Item(sku: 'BOOK-001', qty: -1)),
throwsA(isA<ArgumentError>()),
);
});
});
}
Run:
flutter test test/cart_test.dart
flutter test # all tests
flutter test --coverage # produces coverage/lcov.info
The LCOV output feeds lcov-analysis (in the qa-test-reporting plugin).
Per flutter-testing-doc, widget tests "verify the UI looks and interacts as expected":
// test/cart_screen_test.dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:my_app/cart_screen.dart';
void main() {
testWidgets('CartScreen shows item count', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: CartScreen(initialCount: 3)));
expect(find.text('3 items'), findsOneWidget);
expect(find.byKey(Key('add-to-cart-button')), findsOneWidget);
});
testWidgets('Tapping add button increments count', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: CartScreen(initialCount: 0)));
await tester.tap(find.byKey(Key('add-to-cart-button')));
await tester.pump(); // rebuild after state change
expect(find.text('1 item'), findsOneWidget);
});
}
tester.pumpWidget(...) mounts the widget tree. tester.pump()
advances the frame; tester.pumpAndSettle() advances until no
animations are pending.
Finders:
| Finder | Use |
|---|---|
find.byKey(Key(...)) | By Key (preferred for stable lookups). |
find.text("...") | By visible text (translation-fragile). |
find.byType(Widget) | By widget type. |
find.byIcon(Icons.x) | By Material icon. |
find.descendant(of:, matching:) | Nested matching. |
Per flutter-testing-doc, integration tests "test complete app or large app sections" on real devices.
// integration_test/checkout_flow_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:my_app/main.dart' as app;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('checkout flow', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
await tester.tap(find.byKey(Key('login-button')));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(Key('email-field')), '[email protected]');
// ... etc.
});
}
Run:
# On a connected device or simulator/emulator
flutter test integration_test/checkout_flow_test.dart
For mocks:
// test/cart_test.dart
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'cart_test.mocks.dart'; // generated
@GenerateMocks([CartRepo])
void main() {
test('Cart loads from repo', () async {
final mockRepo = MockCartRepo();
when(mockRepo.getCart()).thenAnswer(
(_) async => Cart(items: [Item(sku: 'BOOK-001', qty: 1)]),
);
final cart = await mockRepo.getCart();
expect(cart.itemCount, 1);
verify(mockRepo.getCart()).called(1);
});
}
Generate the *.mocks.dart files:
dart run build_runner build --delete-conflicting-outputs
flutter test --coverage # writes coverage/lcov.info
genhtml coverage/lcov.info -o coverage/html # human report
The LCOV file feeds the same parser other plugins use
(lcov-analysis)
for cross-language coverage aggregation.
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: subosito/flutter-action@v2
with:
channel: stable
- run: flutter pub get
- run: dart run build_runner build --delete-conflicting-outputs
- run: flutter test --coverage
- uses: codecov/codecov-action@v5
with:
files: coverage/lcov.info
integration-android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: subosito/flutter-action@v2
- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
script: flutter test integration_test/
Per flutter-testing-doc, Flutter supports CI integration via "Fastlane / Travis CI / Cirrus CI / Codemagic / Bitrise / Appcircle / Patrol (for native platform interactions)."
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| All tests as integration tests | Slow; fragile; hides per-layer issues per the pyramid. | Many unit + widget; few integration (Step 1 pyramid). |
find.text("...") for translatable strings | Translation breaks tests. | find.byKey(Key("...")) (Step 3). |
tester.pump() (single frame) for animations | Animation isn't done; assertion fires too early. | tester.pumpAndSettle() for animations. |
Skipping IntegrationTestWidgetsFlutterBinding.ensureInitialized() | Integration test won't bind; runtime errors. | Add as first line in main() (Step 4). |
Mock without @GenerateMocks (manual mock classes) | Tedious; drift when the SUT interface changes. | Use @GenerateMocks + build_runner (Step 5). |
| Coverage from integration tests only | Integration coverage is sparse; misses unit-level branches. | Coverage from flutter test (which runs unit + widget). |
flutter drive deprecated for new projects. Use
integration_test package (modern; Step 4).patrol or
per-platform native integration.Stub for MediaQuery etc. Surface
varies vs production; widget tests don't cover layout/font issues
that need a real renderer.flutter test / flutter drive commands.xcuitest-suite,
espresso-suite,
detox-testing - alternative
framework wrappers when the app isn't Flutter.lcov-analysis - downstream consumer of flutter test --coverage.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub testland/qa --plugin qa-mobile8 skills in this plugin
/appium-testingUse for any question or task about Appium mobile UI tests, even a quick fix, including tests that break after an Appium upgrade and suites that pass on Android but fail on iOS: one suite for iOS and Android (native or React Native) with XCUITest, UiAutomator2 and Espresso drivers, capabilities, clients in JS, Python, Java, Ruby or .NET, simulators, emulators and device farms./detox-testingUse whenever a React Native app needs end-to-end tests with Detox: gray-box runs inside the app, by.id, by.text and by.label matchers, waitFor for extra sync, and the Jest runner. Flutter is flutter-testing; cross-platform black-box is appium-testing; YAML flows are maestro-flows./espresso-suiteUse whenever an Android app needs UI tests in Google's Espresso: onView with perform and check, automatic synchronization instead of sleeps, IdlingResource for app async work, ./gradlew connectedAndroidTest and JUnit XML results./maestro-flowsUse for any question or task about Maestro, even writing one short flow, or a mobile UI test format that product managers and other non-engineers can read and edit: .maestro/*.yaml with tapOn, inputText, assertVisible and swipe, for iOS, Android, Flutter, React Native and web, with nested flows and JavaScript hooks./mobile-a11y-test-authorUse when an iOS or Android app needs accessibility tests: XCUITest performAccessibilityAudit (iOS 17+), VoiceOver labels and traits, Espresso AccessibilityChecks, Accessibility Scanner and TalkBack order, plus WCAG checks for labels, 44pt and 48dp touch targets, contrast and focus order./mobile-device-matrix-toolkitUse when deciding which iOS and Android devices and OS versions to test on at each stage to control CI cost: smoke per PR, regression per merge, full farm at release. Generates Appium configs per device from one YAML, runs a GitHub Actions matrix and merges JUnit results into one table.2 plugins ship this exact skill · first indexed Nov 12, 2026
Other plugins' skills for the same job