integration_test package to Patrol, unlocking powerful native automation capabilities and improved test ergonomics.
Why Migrate to Patrol?
Patrol extends Flutter’sintegration_test with game-changing features:
- Native Platform Access: Interact with permission dialogs, notifications, WebViews, and system settings
- Better Finders: Cleaner, more intuitive syntax for finding widgets
- Hot Restart: Fast test iteration with
patrol develop - Test Isolation: Proper test isolation and sharding support
- Device Farm Support: Works with Firebase Test Lab, BrowserStack, LambdaTest, and more
- Web Testing: Test Flutter web applications (Patrol 4.0+)
- DevTools Extension: Inspect native views directly in Flutter DevTools
Patrol is fully compatible with
integration_test - you can use both in the same project during migration.Prerequisites
Before starting the migration:- Flutter SDK 3.16 or higher (required for Patrol 4.x)
- Existing tests using Flutter’s
integration_testpackage - Basic understanding of Flutter integration testing
Migration Overview
The migration process involves:Step 1: Install Patrol
Install Patrol CLI
Patrol requires a dedicated CLI tool for running tests:Add Patrol Package
Addpatrol to your dev_dependencies:
You can keep
integration_test in your dependencies during migration to run both test types.Step 2: Configure Patrol
Update pubspec.yaml
Add apatrol configuration section to your pubspec.yaml:
pubspec.yaml
Find your package name in
android/app/build.gradle (look for applicationId) and bundle ID in ios/Runner.xcodeproj/project.pbxproj (look for PRODUCT_BUNDLE_IDENTIFIER).Configure Test Directory (Optional)
By default, Patrol looks for tests inpatrol_test/, but you can configure it to use your existing integration_test/ directory:
pubspec.yaml
We recommend creating a separate
patrol_test/ directory to keep Patrol tests separate from legacy integration_test tests during migration.Set Up Native Integration
Patrol requires native platform integration for full functionality.Step 3: Convert Your First Test
Let’s migrate a simple integration test to Patrol.Before: integration_test
integration_test/app_test.dart
After: Patrol
patrol_test/app_test.dart
Key Differences
| integration_test | Patrol |
|---|---|
IntegrationTestWidgetsFlutterBinding.ensureInitialized() | Not needed - automatic |
testWidgets() | patrolTest() |
WidgetTester tester | PatrolIntegrationTester $ |
app.main() | await $.pumpWidgetAndSettle(MyApp()) |
find.text('0') | $('0') |
find.byIcon(Icons.add) | $(Icons.add) |
tester.tap() + tester.pumpAndSettle() | await $(widget).tap() |
Patrol’s finders automatically handle settling after actions, making tests more concise.
Step 4: Advanced Migration Patterns
Finding Widgets
Interacting with Widgets
Waiting and Expectations
Step 5: Leverage Patrol’s Native Automation
Now for the exciting part - add native automation that wasn’t possible withintegration_test:
patrol_test/app_test.dart
This level of native interaction is impossible with
integration_test alone!Step 6: Run Your Migrated Tests
Running Patrol Tests
Use
patrol develop during test development for fast iteration with hot restart!Running in CI
.github/workflows/test.yml
Migration Checklist
Use this checklist to track your migration progress:Setup
- Install Patrol CLI with
patrol doctorpassing - Add
patroltodev_dependencies - Configure
patrolsection inpubspec.yaml - Set up Android native integration
- Set up iOS native integration
Test Conversion
- Create
patrol_test/directory (or configuretest_directory) - Convert
testWidgets()topatrolTest() - Replace
WidgetTesterwithPatrolIntegrationTester - Update finders to use
$()syntax - Remove manual
pumpAndSettle()calls after actions - Replace
app.main()with$.pumpWidgetAndSettle()
Verification
- Run tests with
patrol test - Verify all tests pass
- Test on multiple devices/platforms
- Update CI configuration
Gradual Migration Strategy
You don’t have to migrate everything at once:Migrate Incrementally
Migrate one test file at a time:
- Move file from
integration_test/topatrol_test/ - Convert the test code
- Verify it works
- Move to next file
Troubleshooting
Common Issues
Key Takeaways
Patrol is a superset of integration_test: All your existing integration test knowledge applies. Patrol adds:
- Better finder syntax
- Native automation capabilities
- Improved development experience
- Better test isolation and reliability
Next Steps
Now that you’ve migrated to Patrol, explore its powerful features:- Native Automation: Learn about platform automation
- Finders: Master Patrol’s finder system
- Hot Restart: Speed up development with
patrol develop - Best Practices: Read Effective Patrol
- DevTools Extension: Try the Patrol DevTools Extension
- Web Testing: Explore web testing capabilities
Need Help?
If you encounter issues during migration:- Check the documentation
- Review example tests
- Visit GitHub to report issues
- Join our Discord community for support