Testing Flutter Apps Gets Faster - Hot Restart in Patrol Framework

Rating: 5.00 / 5 Based on 10 reviews

Free product design tips
Join our newsletter and get insights that will change your product design perspective
By submitting your email you agree to receive the content requested and to LeanCode's Privacy Policy.
or follow us

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.

Hot Restart

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

Under the hood

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.

Caveats

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.

Give Patrol a try

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.

Free product design tips
Join our newsletter and get insights that will change your product design perspective
By submitting your email you agree to receive the content requested and to LeanCode's Privacy Policy.
or follow us
Rate this article
5.00 / 5 Based on 10 reviews

Read more

Patrol 1.0 - Powerful Flutter UI Testing Framework

The first stable version of Patrol – a powerful, open-source UI testing framework for Flutter apps is out there, waiting for you to use it. Today, we put the “1.0” sticker on it. Find out how Patrol was born, our vision for it, what we improved, and what it is capable of now.
Testing Flutter Apps Patrol 1.0

Background Services in Flutter Add-to-App Case

As part of a PoC for a client from the banking sector, we had to implement a business process that required some work to be performed in the background in a Flutter module. See our case and code examples of implementing background services in Flutter add-to-app.
Background services in Flutter add-to-app

Right to Left (RTL) in Flutter App - Developer's Guide

Find the most important things to keep in mind when introducing RTL design in your Flutter mobile app and how you can use Flutter to support various text directions with little effort. Follow the guide on RTL prepared by Flutter Developer.
RTL in Flutter by LeanCode