This guide provides comprehensive instructions for testing the Flutter Test Pilot framework.
test/
├── unit/ # Unit tests (organized by module)
│ ├── core/
│ │ └── cache_manager_test.dart
│ ├── executor/
│ │ ├── retry_handler_test.dart
│ │ └── parallel_executor_test.dart
│ └── discovery/
│ └── test_finder_test.dart
├── comprehensive_test.dart # Manual comprehensive tests
├── flutter_test_pilot_test.dart # Main library tests
└── flutter_test_pilot_method_channel_test.dart
example/integration_test/
└── comprehensive_app_test.dart # Integration tests
flutter testflutter test test/unit/core/cache_manager_test.dartflutter test --coveragecd example
flutter test integration_test/comprehensive_app_test.dartThe test_runner.sh script provides an easy way to run different test suites:
./test_runner.sh./test_runner.sh --all./test_runner.sh --integration./test_runner.sh --comprehensive./test_runner.sh --coverage# Unit tests + Integration tests with coverage
./test_runner.sh --all --coverage
# Only comprehensive tests
./test_runner.sh --comprehensiveFast, isolated tests for individual components:
- CacheManager Tests: Cache operations, entry storage/retrieval
- RetryHandler Tests: Retry logic, error detection, backoff strategies
- ParallelExecutor Tests: Concurrent execution, device distribution
- TestFinder Tests: Test file discovery, metadata extraction
Run with:
flutter test test/unit/Full app flow tests using the test_suite API:
- Form interactions
- Navigation flows
- API testing
- Gesture handling
- Wait conditions
Prerequisites:
- Connected device or running emulator
- Example app built
Run with:
cd example
flutter test integration_test/comprehensive_app_test.dartManual validation tests for native features:
- ADB Commander
- Permission Granter
- Dialog Watcher
- Native Handler
- Screenshot Capturer
Prerequisites:
- Android device connected (for device-specific tests)
- ADB installed and in PATH
Run with:
dart test/comprehensive_test.dart# Generate coverage data
flutter test --coverage
# Install lcov (if not already installed)
# macOS:
brew install lcov
# Linux:
sudo apt-get install lcov
# Generate HTML report
genhtml coverage/lcov.info -o coverage/html
# Open report
open coverage/html/index.html # macOS
xdg-open coverage/html/index.html # Linuxlcov --summary coverage/lcov.infoimport 'package:flutter_test/flutter_test.dart';
void main() {
group('YourClass', () {
late YourClass instance;
setUp(() {
instance = YourClass();
});
tearDown(() {
// Cleanup
});
test('should do something', () {
// Arrange
final input = 'test';
// Act
final result = instance.doSomething(input);
// Assert
expect(result, equals('expected'));
});
});
}import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_test_pilot/flutter_test_pilot.dart';
void main() {
testWidgets('should test feature', (WidgetTester tester) async {
final testSuite = TestSuite(
name: 'Feature Test',
description: 'Testing a specific feature',
steps: [
TapAction.text('Button'),
VerifyWidget(finder: find.text('Expected Text')),
Wait.forDuration(Duration(seconds: 1)),
],
);
final results = await testSuite.execute(tester);
expect(results.status, TestStatus.passed);
});
}name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
- run: flutter pub get
- run: flutter test --coverage
- uses: codecov/codecov-action@v3test:
image: cirrusci/flutter:stable
script:
- flutter pub get
- flutter test --coverage
coverage: '/lines\.*: \d+\.\d+\%/'flutter test test/unit/core/cache_manager_test.dart --name "should save and retrieve"flutter test --verboseflutter test --start-pausedAdd to .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Flutter Test",
"type": "dart",
"request": "launch",
"program": "test/unit/core/cache_manager_test.dart"
}
]
}- Keep tests fast: Unit tests should run in milliseconds
- Isolate tests: Use
setUpandtearDownproperly - Use descriptive names: Test names should explain what they test
- Follow AAA pattern: Arrange, Act, Assert
- Mock external dependencies: Don't rely on network or file system
- Test edge cases: Include error scenarios
- Maintain test coverage: Aim for 80%+ coverage
# Clear test cache
flutter clean
rm -rf build/
flutter pub get# Increase timeout
flutter test integration_test/ --timeout=5m# Add ADB to PATH
export PATH=$PATH:$ANDROID_HOME/platform-tools# Ensure test package is available
flutter pub add --dev test
flutter test --coverageWhen adding new features, please include:
- Unit tests for business logic
- Integration tests for UI flows (if applicable)
- Update this README if new test patterns are introduced
- Ensure all tests pass before submitting PR
# Before committing
./test_runner.sh --all