The Key to Widget Testing

Greg Perry
Flutter Community
Published in
16 min readJan 15, 2021

--

An in-depth look at Testing in Flutter.

Unfortunately, I inadvertently deleted the source code for this article. It’s a good read, but without the code, it’s not stellar. Give it go, and I’ll have another example app to work with one day.

You’ve got to test your code. It’s a given. You’ve got to make sure it works, but like documentation, we programmers tend to write our test cases almost as an afterthought. Some shops, however, dedicate whole departments just to testing. Someone else then tests your code! Flutter offers a whole platform just for testing your code. Let’s take a look at how it’s done.

There’s A Test For That

In every new Flutter project, you‘ll find a directory called, test. In this article, we’re going to look at the test file, widget_test.dart, found in that directory for this particular Flutter project below called, mvc_template. You’ll have access to the Github account for this project (Again, I mistakenly deleted this project). It’s to produce a ‘project template’ involving the MVC design pattern for developers to start their own apps, but that’s another story. Here, we’re testing its accompanying example app.

mvc_template

I Like Screenshots. Tap Captions For Gists.

As always, I prefer using screenshots in my articles over gists to show concepts rather than just show code. I find them easier to work with frankly. However, you can click or tap on their captions to see the code in a gist or in Github. Tap or click on the screenshots themselves to zoom in on them.

No Moving Pictures, No Social Media

There will be gif files in this article demonstrating aspects of the topic at hand. However, it’s said viewing such gif files is not possible when reading this article on platforms like Instagram, Facebook, etc. They may come out as static pictures or simply blank placeholder boxes. Please, be aware of this and maybe read this article on medium.com

Let’s begin.

--

--