Flutter Widget and Integration Tests — some Surprises about Timeouts and Durations

Alfred Schilken
7 min readDec 26, 2021

I’ve been working on a big Flutter project for half a year now. One of my tasks is writing integration tests. In this article I summarize what I have learned about timouts.

You will learn:

  • how to fail early when pumpAndSettle() waits on endless running animations.
  • how to set the default timeout for all widgetTests.
  • some surprises of time and size when running widgetTests.

Preparation of a Tiny Project

I modified the standard counter app for a little experiment:

  • I removed the floating action button and replaced it with a timer which increases the _counter every second.
  • I added an endless running CircularProgressIndicator.
  • I figured out the size of the widget using context.findRenderObject().

Here I start the timer in initState():

The build-method looks like this:

First it gets the size of the widget. When running a widget test the size is printed to the console, an integration test will also show the size on the screen. The _counter value is displayed and below this a Progressindicator will show up forever.

Here is a screenshot of this tiny test app running on an android emulator:

The counter will run until the app is closed — always displaying the animating progress indicator. Note the size of the widget. That’s the real pixel size of the Pixel 2…

Alfred Schilken

Software Developer for more than 35 years, started with C and C++, after Java, Python, Groovy, Lua, Golang and Swift now focussing on Dart and Flutter