If you want to use Patrol finders in your existing widget or golden tests, see Using Patrol finders in widget tests.
Prerequisites
Before you begin, make sure you have:- Flutter SDK 3.32.0 or higher
- Dart SDK 3.8.0 or higher
- An Android emulator or iOS simulator (or physical device)
- Xcode (for iOS/macOS testing) or Android Studio (for Android testing)
Installation
Install patrol_cli
The Patrol CLI is required to run integration tests. Install it globally:Verify the installation:
Check your environment
Run Example output:Make sure all checks are green for the platform you want to test.
patrol doctor to verify your environment is set up correctly:Add Patrol to your project
Add This adds the following to your
patrol as a dev dependency:pubspec.yaml:pubspec.yaml
Configure patrol in pubspec.yaml
Add a
patrol section to your pubspec.yaml with your app details:pubspec.yaml
Where do I find package_name and bundle_id?
Where do I find package_name and bundle_id?
Android package name:
- Open
android/app/build.gradle - Look for
applicationIdin thedefaultConfigsection
- Open
ios/Runner.xcodeproj/project.pbxproj - Search for
PRODUCT_BUNDLE_IDENTIFIER - Or open your project in Xcode and check the General tab
By default, Patrol looks for tests in
patrol_test/. To use a different directory, add:pubspec.yaml
Set up native integration
Patrol needs to integrate with your app’s native code to enable full testing capabilities.
Create your first test
Create a test file at
patrol_test/example_test.dart:patrol_test/example_test.dart
This is a simple test to verify Patrol is working. In real tests, you’d pump your actual app widget.
What’s Next?
Congratulations! You’ve successfully set up Patrol and run your first test. Here’s what to explore next:Write Your First Real Test
Follow a comprehensive tutorial to write a full integration test with native interactions
Learn Custom Finders
Master Patrol’s intuitive finder syntax to write cleaner tests
Explore Native Automation
Learn how to interact with permissions, notifications, and system UI
CLI Commands
Discover all the patrol CLI commands and their options
Troubleshooting
Test bundle error or version mismatch
Test bundle error or version mismatch
This usually means your
patrol and patrol_cli versions are incompatible.Check the compatibility table and ensure you’re using compatible versions.Android: Unsupported class file major version
Android: Unsupported class file major version
This is caused by using an incompatible JDK version. Patrol officially supports JDK 17.Check your JDK version:In Android Studio/IntelliJ, go to Settings → Build, Execution, Deployment → Build Tools → Gradle → Gradle JDK and select JDK 17.
iOS: Simulator gets cloned when running tests
iOS: Simulator gets cloned when running tests
This happens when parallel execution is enabled in Xcode.To fix:
- Open your project in Xcode
- Go to Product → Scheme → Edit Scheme
- Select Test from the left sidebar
- Uncheck Execute in parallel
- Repeat for all schemes if you have multiple
iOS: Wait for [app] to idle
iOS: Wait for [app] to idle
This is usually caused by leftover
FLUTTER_TARGET configuration.Search for FLUTTER_TARGET in your *.xcconfig and *.pbxproj files and remove both the key and value.Then regenerate the configuration:Can't pump my app in tests
Can't pump my app in tests
Make sure you’re NOT calling:
WidgetsFlutterBinding.ensureInitialized()- Patrol handles thisrunApp()- Use$.pumpWidgetAndSettle()instead- Modifying
FlutterError.onError- This breaks test error handling
Initializing Your App in Tests
To test your real app, you need to initialize it properly inside the test. Here are the key rules: Good example:patrol_test/app_test.dart
Using Flavors
If your app uses flavors, specify them inpubspec.yaml:
pubspec.yaml
Add to .gitignore
Patrol generates a test bundle file that should not be committed:.gitignore
Get Help
If you’re stuck:- Check the FAQ
- Join the Patrol Discord server
- Ask on GitHub Discussions
Ready for more?
Continue to the comprehensive tutorial to write a real-world test with native interactions