Rating: 5.00 / 5 Based on 10 reviews
Patrol, our UI testing framework for Flutter apps, gets a steady stream of updates. In one of the recent ones, we implemented a very cool new feature –– Hot Restart, which lets developers and QA teams develop tests even faster. Patrol, in general, makes user interface testing more efficient and easier.
In this article, we'd like to tell you more about the newest update in Patrol 1.1 - Hot Restart, so keep reading.
If you want to use it right away, go to: Patrol's documentation.
The new `patrol develop` runs tests mostly like the already present `patrol test` command, with the added benefit of Hot Restart. This feature speeds up the app development process by allowing developers to run their tests without having to rebuild their entire app every time.
To use the Hot Restart feature, developers can simply specify the --target option when running a test file:
patrol develop --target integration_test/example_test.dart
After a usual build process, the app will start, and the Hot Restart feature will become active. To trigger a Hot Restart, simply type R.
Here you can watch a video that shows how it works
As cool as it looks, getting Hot Restart to work with Patrol (our open-source framework dedicated to Flutter automated UI testing) was a low-hanging fruit.
Most Flutter devs use the flutter run command to build, install, run, and debug apps. But when you execute patrol test (or patrol develop) in the terminal, no flutter run is called under the hood. That's because the default flutter run doesn't support the integration testing features that Patrol needs to work. Instead, Patrol calls native build systems (Gradle on Android and xcodebuild on iOS) to build the app for testing.
After the app is built, installed, and run, you probably want to get some logs from it. Fortunately, a less-known flutter attach command exists, which allows for exactly that – it attaches to the running Flutter app, giving you the same familiar experience you're used to when using flutter run. That means logs and… Hot Restart!
So, to sum up: to enable Hot Restart for Patrol tests, we modified patrol_cli to always call flutter attach after the app runs on the device. Then, every time you press the "r" key in the terminal, patrol_cli simply forwards that "r" to flutter attach, and it takes care of Hot Restart.
While the Hot Restart feature is powerful, there are some important limitations to keep in mind. We don't like sugarcoating, so we will first share the biggest problem – patrol develop doesn't work on physical iOS devices. Unfortunately, after closer investigation, we're pretty sure it's a bug in the flutter attach command. We reported it to Flutter – and we'd be grateful if you gave it the thumbs-up to raise its visibility.
Hot Restart only restarts the Flutter part of the app and not the native part. Additionally, the app's data is not cleared, and permissions that have been granted cannot be revoked. These limitations stem directly from how Flutter and Android/iOS work, and as much as we'd like to fix them, there's nothing we can do. To learn more about them, visit the documentation of the `patrol develop` command.
It's important to write the tests with these caveats in mind to ensure they're accurate and reliable. Despite these limitations, we're confident that the Hot Restart feature is a game-changer for developers using Patrol to create integration tests for their Flutter apps.
So that's it for now. We're really excited about Hot Restart – so far, everybody who has used it said it makes the day and night difference! To ensure you're on the latest patrol and patrol_cli versions (Patrol 1.1), which support Hot Restart and contain all the latest bug fixes, simply run patrol update.
If you want to catch up on what Patrol can do, return to our earlier article about Patrol 1.0.
The newest update: Patrol has reached version 2.0.