flutter-add-integration-test
Configure and run integration tests using the integration_test package with Flutter Driver. Use when testing complete user flows, verifying navigation, or running end-to-end tests on devices or CI.
What this skill does
## Contents
- [Project Setup](#project-setup)
- [Test Authoring](#test-authoring)
- [Execution Targets](#execution-targets)
- [Performance Profiling](#performance-profiling)
- [CI/CD Integration](#ci-cd-integration)
- [Common Pitfalls](#common-pitfalls)
- [Workflow: Adding an Integration Test](#workflow-adding-an-integration-test)
- [Examples](#examples)
## Project Setup
1. Add required development dependencies to `pubspec.yaml`:
```bash
flutter pub add 'dev:integration_test:{"sdk":"flutter"}'
flutter pub add 'dev:flutter_test:{"sdk":"flutter"}'
```
2. Create directory structure:
```
project_root/
├── integration_test/
│ └── app_test.dart # Test cases
└── test_driver/
└── integration_test.dart # Host driver script
```
3. Create the host driver script at `test_driver/integration_test.dart`:
```dart
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() => integrationDriver();
```
4. Add `ValueKey`s to critical widgets in production code for reliable targeting:
```dart
FloatingActionButton(
key: const ValueKey('increment_fab'),
onPressed: _increment,
child: const Icon(Icons.add),
)
```
## Test Authoring
- Initialize the binding at the top of `main()` — this replaces the default test binding.
- Load the full application with `tester.pumpWidget(const MyApp())`.
- Use `tester.pumpAndSettle()` after every interaction to wait for animations and async operations.
- Assert widget visibility using `expect(find.byKey(ValueKey('foo')), findsOneWidget)`.
- Scroll to off-screen widgets using `tester.scrollUntilVisible(finder, 500.0)`.
### Test File Structure
```dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:my_app/main.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('End-to-end test', () {
testWidgets('complete user flow', (tester) async {
// Load full app
await tester.pumpWidget(const MyApp());
// Interact with widgets
await tester.tap(find.byKey(const ValueKey('login_button')));
await tester.pumpAndSettle();
// Assert navigation happened
expect(find.byType(HomePage), findsOneWidget);
});
});
}
```
## Execution Targets
Choose the execution method based on target platform:
### Local Device (Android/iOS)
```bash
flutter test integration_test/
```
### Chrome (Web)
```bash
# Terminal 1: Start ChromeDriver
chromedriver --port=4444
# Terminal 2: Run tests
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/app_test.dart \
-d chrome
```
### Headless Web
```bash
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/app_test.dart \
-d web-server
```
### Firebase Test Lab (Android)
```bash
# 1. Build debug APK
flutter build apk --debug
# 2. Build instrumentation test APK
pushd android && ./gradlew app:assembleAndroidTest && popd
# 3. Upload both APKs to Firebase Test Lab via console or gcloud:
gcloud firebase test android run \
--type instrumentation \
--app build/app/outputs/flutter-apk/app-debug.apk \
--test build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk
```
## Performance Profiling
Wrap test actions in `binding.traceAction()` to capture performance timelines:
```dart
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('scrolling performance', (tester) async {
await tester.pumpWidget(const MyApp());
await binding.traceAction(() async {
final listFinder = find.byType(Scrollable);
await tester.fling(listFinder, const Offset(0, -500), 10000);
await tester.pumpAndSettle();
}, reportKey: 'scrolling_timeline');
});
}
```
### Performance Profiling Driver
Use this driver to capture and write timeline data:
```dart
import 'package:flutter_driver/flutter_driver.dart' as driver;
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() {
return integrationDriver(
responseDataCallback: (data) async {
if (data != null) {
final timeline = driver.Timeline.fromJson(
data['scrolling_timeline'] as Map<String, dynamic>,
);
final summary = driver.TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(
'scrolling_timeline',
pretty: true,
includeSummary: true,
);
}
},
);
}
```
## CI/CD Integration
### GitHub Actions Workflow
```yaml
- name: Run integration tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 33
script: flutter test integration_test/ --flavor dev
```
- Use `reactivecircus/android-emulator-runner` for Android emulator.
- Collect test result artifacts with `actions/upload-artifact`.
- For web, run `chromedriver` as a service and test with `-d chrome`.
## Common Pitfalls
| Error | Cause | Fix |
|---|---|---|
| `PumpAndSettleTimedOutException` | Infinite animation (e.g., `CircularProgressIndicator`) | Use `pump()` instead, or dismiss the loading state |
| Widget not found | Lazy-loaded in `SliverList` or `ListView` | Call `scrollUntilVisible()` before interacting |
| Test hangs | Network call in production code | Mock HTTP client or use `--dart-define` to bypass |
| `No host driver specified` | Missing `test_driver/integration_test.dart` | Create the host driver file |
## Workflow: Adding an Integration Test
### Task Progress
- [ ] **Step 1**: Add `integration_test` and `flutter_test` to `dev_dependencies`.
- [ ] **Step 2**: Assign `ValueKey`s to target widgets in production code.
- [ ] **Step 3**: Create `integration_test/app_test.dart` with binding initialization.
- [ ] **Step 4**: Create `test_driver/integration_test.dart` with `integrationDriver()`.
- [ ] **Step 5**: Write test cases — load app, interact, assert.
- [ ] **Step 6**: Choose execution target:
- Local device: `flutter test integration_test/`
- Chrome: `flutter drive ... -d chrome`
- Firebase Test Lab: build + upload APKs
- [ ] **Step 7**: Feedback Loop:
- If `PumpAndSettleTimedOutException` → check for infinite animations.
- If widget not found → add `scrollUntilVisible`.
- Re-run until all tests pass.
## Examples
### Standard Integration Test
```dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:my_app/main.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Counter app', () {
testWidgets('tap FAB, verify counter increments', (tester) async {
await tester.pumpWidget(const MyApp());
// Verify initial state
expect(find.text('0'), findsOneWidget);
// Tap the increment button
final fab = find.byKey(const ValueKey('increment_fab'));
await tester.tap(fab);
await tester.pumpAndSettle();
// Verify counter incremented
expect(find.text('1'), findsOneWidget);
});
});
}
```
### Multi-Screen Navigation Flow
```dart
testWidgets('login and navigate to home', (tester) async {
await tester.pumpWidget(const MyApp());
// Enter credentials
await tester.enterText(find.byKey(const ValueKey('email_field')), '[email protected]');
await tester.enterText(find.byKey(const ValueKey('password_field')), 'password123');
// Submit login
await tester.tap(find.byKey(const ValueKey('login_button')));
await tester.pumpAndSettle();
// Verify navigation to home
expect(find.byType(HomePage), findsOneWidget);
expect(find.byType(LoginPage), findsNothing);
});
```
Related in Cloud & DevOps
appbuilder-action-scaffolder
IncludedCreate, implement, deploy, and debug Adobe Runtime actions with consistent layout, validation, and error handling. Use this skill whenever the user needs to add actions to an App Builder project, understand action structure (params, response format, web/raw actions), configure actions in the manifest, use App Builder SDKs (State, Files, Events, database), deploy and invoke actions via CLI, debug action issues, or implement patterns such as webhook receivers, custom event providers, journaling consumers, large payload redirects, action sequence pipelines, and Asset Compute workers. Also trigger when users mention serverless functions in Adobe context, action logging, IMS authentication for actions, or cron-style scheduled actions.
orchestrating-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. Use this skill when the user needs a multi-step Data Cloud pipeline, cross-phase troubleshooting, or data space and data kit management. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase sf data360 workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching phase-specific skill), the task is STDM/session tracing/parquet telemetry (use observing-agentforce), standard CRM SOQL (use querying-soql), or Apex implementation (use generating-apex).
github-project-automation
IncludedAutomate GitHub repository setup with CI/CD workflows, issue templates, Dependabot, and CodeQL security scanning. Includes 12 production-tested workflows and prevents 18 errors: YAML syntax, action pinning, and configuration. Use when: setting up GitHub Actions CI/CD, creating issue/PR templates, enabling Dependabot or CodeQL scanning, deploying to Cloudflare Workers, implementing matrix testing, or troubleshooting YAML indentation, action version pinning, secrets syntax, runner versions, or CodeQL configuration. Keywords: github actions, github workflow, ci/cd, issue templates, pull request templates, dependabot, codeql, security scanning, yaml syntax, github automation, repository setup, workflow templates, github actions matrix, secrets management, branch protection, codeowners, github projects, continuous integration, continuous deployment, workflow syntax error, action version pinning, runner version, github context, yaml indentation error
sf-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase `sf data360` workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching sf-datacloud-* skill), the task is STDM/session tracing/parquet telemetry (use sf-ai-agentforce-observability), standard CRM SOQL (use sf-soql), or Apex implementation (use sf-apex).
fabric-cli
IncludedUse this skill for Fabric.so CLI workflows with the `fabric` terminal command: diagnose/install/login, search or browse a Fabric library, save notes/links/files, create folders, ask the Fabric AI assistant, manage tasks/workspaces, generate shell completion, check subscription usage, produce JSON output, and use Fabric as persistent agent memory. Do not use for Microsoft Fabric/Azure/Power BI `fab`, Daniel Miessler's Fabric framework, Python Fabric SSH, Fabric.js, or textile/fashion fabric.
lark
IncludedLark/Feishu CLI skills: lark-cli operations for docs, markdown, sheets, base, calendar, im, mail, task, okr, drive, wiki, slides, whiteboard, apps, approval, attendance, contact, vc, minutes, event. Use when the user needs to operate Lark/Feishu resources via lark-cli, send messages, manage documents, spreadsheets, calendars, tasks, OKRs, deploy web pages, or any Feishu/Lark workspace operations.