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()
, andscrollTo()
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 theintegration_test
directory should be added to gitignore. It's automatically generated by Patrol CLI at build time..gitignoreintegration_test/test_bundle.dart
-
In your tests, rename
scrollTo()
's argumentscrollable
toview
.
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.javapackage 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.gradleandroid { // ... 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.gradledefaultConfig { //... 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) independencies
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:
@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.