Patrol Setting Up Patrol Test Estimated reading: 4 minutes 142 views This guide will walk you through the necessary steps to set up Patrol, covering both Android and iOS configurations. By the end, your project will be ready to run integration tests with Patrol, so you can ensure your app’s quality on different platforms.Adding Patrol DependencyTo get started, you’ll need to add the Patrol dependency to your Flutter project. Open your pubspec.yaml file and add the Patrol package under dev_dependencies.pubspec.yamldev_dependencies: patrol: ^3.11.0Once you’ve done this, Patrol will be available for you to run tests in your app.Install Patrol CLIWith the dependency configured, you need to install Patrol’s CLI to run the tests. Simply open your terminal and run:pubspec.yamldart pub global activate patrol_cliThis command will install the Patrol command-line tools required for your testing. Installing Patrol CLI via TerminalVerifying with Patrol DoctorAfter installing the CLI, run the Patrol Doctor to verify that your project is ready for testing. This handy tool will inspect your project and alert you to any potential issues. Use the following command: pubspec.yamlpatrol doctorRunning this ensures that everything is correctly set up and that you can proceed without any errors. Running Patrol DoctorAndroid SetupSetting up Patrol for Android involves a few more steps. First, go to the directory android/app/src/androidTest/java/com/example/myapp/ in your project. If these folders don’t exist, you can create them, but remember to replace /com/example/myapp/ with your app’s package path. Patrol Android Directory SetupNext, modify your build.gradle file, located in the android/app directory. Add the following lines to the defaultConfig section: android/app/build.gradletestInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner" testInstrumentationRunnerArguments clearPackageData: "true" Patrol DefaultConfig SetupIn the android section, include the following configuration: android/app/build.gradletestOptions { execution "ANDROIDX_TEST_ORCHESTRATOR" } Patrol Add TestOptions SnippetFinally, add this line to your dependencies: android/app/build.gradleandroidTestUtil "androidx.test:orchestrator:1.4.2"This setup prepares Patrol to run integration tests on Android, using the orchestrator to manage tests efficiently. Patrol androidTestUtil dependencies snippetiOS SetupTo configure Patrol on iOS, open ios/Runner.xcworkspace in Xcode. Patrol ios Directory To Go To XCodeOnce the project is open, you’ll notice that two files, RunnerUITests.m and RunnerUITestsLaunchTests.m are created.Delete the RunnerUITestsLaunchTests.m file, as it’s not needed. Patrol XCode RunnerUITest.mMake sure the iOS Deployment Target for RunnerUITests is the same as for Runner. A minimum version of iOS 11.0 is required, though you may need to set this to iOS 13.0 depending on your app dependencies. If a test target doesn’t already exist, create one by selecting File > New > Target… and choose UI Testing Bundle. Name the product RunnerUITests, and ensure the Organization Identifier is the same as the main app. The target to be tested should be set to Runner.Replace the contents of RunnerUITests.m with the following code:RunnerUITests.m@import XCTest; @import patrol; @import ObjectiveC.runtime; PATROL_INTEGRATION_TEST_IOS_RUNNER(RunnerUITests) Now, create an empty file called integration_test/example_test.dart in the root of your project. To finalize the setup, run the following commands: Patrol Example Integration Testbashflutter build ios --config-only integration_test/example_test.dart Patrol Build IOS ConfigThen go to your ios directory and run: bashpod install --repo-update Finally, go to RunnerUITests Build Phases and add two new Run Script Phase build phases.Name them xcode_backend build and xcode_backend embed_and_thin, respectively.For xcode_backend build, paste the following script:Run Script Phase: xcode_backend build/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build Patrol Xcode Backend BuildAnd for xcode_backend embed_and_thin:Runner Build Phase: xcode_backend embed_and_thin/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed_and_thin These steps will ensure that your iOS app is ready for Patrol testing.ConclusionWith Patrol fully set up for both Android and iOS, you’re now ready to run comprehensive mobile tests on your Flutter app. This guide walked you through the process of adding dependencies, configuring your project for Patrol, and setting up your testing environment for both platforms. In the next guide, you’ll learn how to write your first Patrol test, taking your mobile app testing to the next level!Tagged:Patrol Patrol - Previous Introduction to Patrol Testing Next - Patrol Writing Your First Patrol Test Case