Testing in Flutter is powerful!

Abhay Sood
2 min readMar 15, 2022

Speed, effectiveness & simplicity of tests in Flutter.

I had posted this a while ago. It was when we had just started building Gojek’s design system — Asphalt Aloha in Flutter.

A few things I loved about writing tests in Flutter:

Speed

So far, we’ve built 50% of our design system components. During the process we have written a total of 341 tests160 unit tests & 181 golden tests.

All tests run locally, including golden tests. On my machine it takes around 30 seconds to run all tests. Also note that, each golden test generates 4 golden files, one each for 4 different themes.

Tests running for Asphalt Aloha in Flutter

Here’s a sneak peak at what the golden tests generate. Isn’t it surreal?

Golden files generated for Asphalt Aloha in Flutter

Effectiveness

With Flutter, you can test close to everything. We have unit tests for behaviour, animations, accessibility & UI across multiple themes (using golden tests).

We’ve got 76% coverage for Asphalt Aloha package.

The real coverage would be around 95% had it not been for a lot of debugFillProperties methods, which have no elegant way to be omitted from coverage reports.

Simplicity

The best part is that writing these tests is as simple as it gets. This cookbook is the best place to get started with testing in Flutter. Go ahead if you haven’t checked it out yet.

Note to developers: with Flutter you can’t blame your PMs or EMs for not giving you enough time to write tests.

What could be better?

The only thing I can think of now is: Move mock_canvas to flutter_test package. Which will allow me to test a crazy canvas drawing for a particular component.

Thanks for reading! 💙

--

--