flutter-testing
БесплатноБез исполняемых скриптовНе проверенUse whenever a Flutter app needs tests: unit tests with flutter test, widget tests with testWidgets and WidgetTester, integration_test on simulators…
от testland★ 18 звёзд на GitHubОб этом скилле
flutter-testing
Overview
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.
When to use
- The app is Flutter (the framework's intended use case).
- The team uses Dart and wants test-stack consistency with production code.
Step 1 - Install
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
Step 2 - Unit tests
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).
Step 3 - Widget tests
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. |
Step 4 - Integration tests
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
Step 5 - Mockito + build_runner
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
Step 6 - Coverage + reporting
flutter test --cover
Установить flutter-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл flutter-testing?
Use whenever a Flutter app needs tests: unit tests with flutter test, widget tests with testWidgets and WidgetTester, integration_test on simulators, emulators or devices, choosing the layer per change, mockito with build_runner, LCOV coverage and CI.
Как установить скилл flutter-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл flutter-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic