LogoPatrol

Patrol 2.0 is here!

Patrol 2.0 is the new major version of Patrol.

Changes#

  • Advanced test bundling feature provides deep and seamless integration with existing Android and iOS testing tools. It also fixes some long-standing Flutter issues:

    This is huge (even though it may not look like it at first glance). To learn more, read the in-depth technical article explaining the nuts and bolts.

  • Improved scrolling and pumping makes methods such as tap(), enterText(), and scrollTo() more reliable and easier to use. For example, they no longer throw an error if there's an infinite animation.

Migration guide#

Patrol 2.0 contains a few breaking changes.

Fortunately, they're small and mostly touch only boilerplate and configuration files. The code of tests written in Dart stays the same (with some minor exceptions - see the Caveats section below).

Common#

  • Update the dependency in pubspec.yaml:

    dev_dependencies:
      patrol: ^2.0.0
    
  • Make sure you're using the newest version of Patrol CLI. It should begin with v2:

    $ patrol --version
    patrol_cli v2.0.0
    
  • The file test_bundle.dart in the integration_test directory should be added to gitignore. It's automatically generated by Patrol CLI at build time.

    .gitignore
    integration_test/test_bundle.dart
    
  • In your tests, rename scrollTo()'s argument scrollable to view.

Android#

  • MainActivityTest.java

    Contents of this file have to be replaced. It's located your application's android/app/src/androidTest/java/com/example/myapp/ directory (replacing com, example, and myapp with values from your app's package name).

    MainActivityTest.java
    package pl.leancode.patrol.example; // replace "pl.leancode.patrol.example" with your app's package
    
    import androidx.test.platform.app.InstrumentationRegistry;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;
    import org.junit.runners.Parameterized.Parameters;
    import pl.leancode.patrol.PatrolJUnitRunner;
    
    @RunWith(Parameterized.class)
    public class MainActivityTest {
        @Parameters(name = "{0}")
        public static Object[] testCases() {
            PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
            instrumentation.setUp(MainActivity.class);
            instrumentation.waitForPatrolAppService();
            return instrumentation.listDartTests();
        }
    
        public MainActivityTest(String dartTestName) {
            this.dartTestName = dartTestName;
        }
    
        private final String dartTestName;
    
        @Test
        public void runDartTest() {
            PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
            instrumentation.runDartTest(dartTestName);
        }
    }
    
  • build.gradle

    A few changes are also needed in app-level build.gradle:

    android/app/build.gradle
    android {
      // ...
      defaultConfig {
        //...
        testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner"
      }
    
      // ...
    
      testOptions {
        execution "ANDROIDX_TEST_ORCHESTRATOR"
      }
    }
    
    dependencies {
      androidTestUtil "androidx.test:orchestrator:1.4.2"
    }
    

    To achieve full isolation between test runs, enable the clearPackageData option:

    android/app/build.gradle
    defaultConfig {
      //...
      testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner"
      testInstrumentationRunnerArguments clearPackageData: "true"
    }
    

    This will clear the app's data and permissions before each test run. Unfortunately, no equivalent feature is available on iOS.

    If you had testImplementation "junit:junit:4.13.2" (or similar) in dependencies block, it should be removed.

iOS#

On iOS, only one line has to be added in the RunnerUITests.m file. Simply copy and paste these contents:

ios/RunnerUITests/RunnerUITests.m
@import XCTest;
@import patrol;
@import ObjectiveC.runtime;

PATROL_INTEGRATION_TEST_IOS_RUNNER(RunnerUITests)

That's all!

Caveats#

There are a few, and all are kept track of in this issue. We intent to fix all of them in future releases.