How to Show Dialogs in Flutter Integration Tests

Alfred Schilken
4 min readDec 27, 2021

What? A test shows a Dialog?

Normally, only your application displays dialogs or alerts. An integration test only runs the application and may check if the correct dialog is displayed. The other day I stumbled across a blog with an example that displays a dialog directly from the test code. I tried it out and it works!

Why Should You Want to do That?

I think there are some cases, where showing dialogs with some info about a running test can be useful:

  • While developing integration tests you will run them often on an emulator and watch what happens on the screen.
  • Most CI services provide a video showing all your tests in one continuous pass. A full integration test run can consist of dozens of individual widgetTests. It‘s not always clear which of the widgetTests is started or whether it finished successfully. A widgetTests just ends and the next one begins immediately or (sometimes) after showing a short "Test starting..." screen. You can't see whether a single test finished because of a failed expectation or whether it was the successful end. As a developer when a test run fails you hopefully get a log and can identify the failing screen. If you don't have such a log or while you are developing it's nice to get a hint…

--

--

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