The New Flutter Integration Tests — Are They any Good?

The Positives

+ Same API

The API does not only look but is the same that is used by widget tests — only the deep internals are different.

+ Runs on device

With widget tests to verify why some tests are not working you just print with debugDumpApp the widget tree— if you are a beginner that widget tree is terrifying due to its size.

+ Referencing Flutter classes

In Flutter Driver tests, you could not reference anything from Flutter, even if you try to import package:flutter/widget.dart file, your tests will fail and if you do not know why it is happening, good luck resolving that.

+ No need for connection to desktop

In the Flutter Driver, your tests were actually running on your desktop and communicating with the application on the tested device.

+ Independent Tests

In Flutter Driver all the tests started where the previous finished — if you navigated to a new page in one test, in the next one you would still be on that page.
In Integration Tests, tests are independent and that makes writing them much easier.

The Negatives

- No Virtual Time:

The virtual time you can manipulate at will — Widget tests support virtual time by default and if you have a delay in your code eg Future<void>.delayed(const Duration(seconds: 10) or long-running animation, it will instantly finish.

- No Screenshots

Before the tests were run on the desktop but the app was running on the devices (now everything is run on the device).

- End to End testing

By End To End (e2e) testing, I mean that you do not mock your http requests and rely on a hopefully stable staging environment. The mocked tests should be the majority of your tests but having some e2e test is also valuable.

- Need to be run separately

The command for Integration Tests does not allow us to run all test files from a folder — the way we are used to in Unit and Widget tests. For now, you can run one file at a time:

flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/main_test.dart

Conclusion

Should you migrate all your tests now?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tomek Polański

Tomek Polański

Passionate mobile developer. One thing I like more than learning new things: sharing them