Understand how Patrol ensures tests run independently with full isolation and support for parallel execution and sharding
Test isolation is crucial for reliable, maintainable test suites. Patrol provides multiple mechanisms to ensure each test runs in a clean environment, independent of other tests. This page explains how isolation works and how to configure it for your needs.
On iOS Simulator, Patrol provides the --full-isolation flag:
patrol test --full-isolation
This flag enables per-test isolation:
1
Before each test
Simulator is cloned to a fresh instance
2
During test
Test runs on the cloned simulator
3
After test
Cloned simulator is deleted
4
Next test
Process repeats with a new clone
iOS Full Isolation is ExperimentalThe --full-isolation flag for iOS is experimental and may be removed or changed in future releases. Use it with caution in production CI/CD pipelines.It’s also only available on iOS Simulator, not on physical devices.
Patrol scans your test directory (default: patrol_test/) for files ending in _test.dart
2
Bundle Generation
Creates test_bundle.dart containing all test references:
test_bundle.dart (generated)
// This file is generated by Patrol CLIimport 'login_test.dart' as login_test;import 'signup_test.dart' as signup_test;import 'profile_test.dart' as profile_test;void main() { login_test.main(); signup_test.main(); profile_test.main();}
3
Native Test Setup
Native instrumentation (Android JUnit / iOS XCTest) lists all tests and runs them individually
4
Isolated Execution
Each test runs in isolation per platform configuration
Add to .gitignore:
patrol_test/test_bundle.dart
This file is auto-generated and should not be committed.
# Run 1st shard of 3 totalpatrol test --device chrome --web-shard=1/3# Run 2nd shard of 3 total patrol test --device chrome --web-shard=2/3# Run 3rd shard of 3 totalpatrol test --device chrome --web-shard=3/3
While Patrol doesn’t have built-in mobile sharding, you can implement it manually:
# Run first half of testspatrol test \ --target test1.dart \ --target test2.dart \ --target test3.dart# Run second half of testspatrol test \ --target test4.dart \ --target test5.dart \ --target test6.dart
Test Isolation Checklist:✅ Enable clearPackageData on Android✅ Use --full-isolation on iOS Simulator (when needed)✅ Initialize fresh state at test start✅ Avoid global mutable state✅ Clean up resources in finally blocks✅ Don’t rely on test execution order✅ Make tests idempotent - safe to run multiple times✅ Add test_bundle.dart to .gitignore✅ Test in isolation AND in full suite✅ Consider sharding for large test suites