Thursday, March 24, 2022

Strategy for Implementing and Using Autotests in Flutter

Full testing requires both Widget and E2E tests.

Widget tests. Well suited for launching on pull requests. They work on mock data and pass several times faster.

E2E tests. It is necessary to test the application on full user scenarios and a real server - otherwise it is difficult to assert that the system is fully operational. At the same time, it is not advisable to run them, for example, on pull requests: E2E tests are slow and unstable. Their instability is not in the way they are written, but in the infrastructure: the server can always crash, some request may fall off, or a system dialog will appear on a real device. All this will drop the test.

Autotests are most useful if you run them on stable features as often as possible.


New package

At the end of 2020, Flutter updated the flutter_test package. Prior to this, Flutter worked with Widget and E2E tests separately.

For Widget components, there was a WidgetTester class. It allowed downloading a Widget and checking it out. For E2E, the FlutterDriver class. It loaded the application and allowed you to simulate interaction with the interface. Now only WidgetTester remains: Flutter has deprecated the driver approach.

The first thing that catches your eye is that everything has become easier. E2E tests now work through the same API as Widget tests - inside the flutter_test package via WidgetTester. Therefore, it has become easier to implement support for Widget and E2E tests at the same time.

No comments:

Post a Comment

Strategy for Implementing and Using Autotests in Flutter

Full testing requires both Widget and E2E tests. Widget tests. Well suited for launching on pull requests. They work on mock data and pass s...