The ultimate guide to testing in Flutter

Tomic Riedel
5 min readSep 5, 2022

Testing is an area in programming, that is very important, but no one really likes it. We still have to learn it, and that’s why I will show you, how to test in Flutter. We will take a look at Unit Testing, Widget Testing, and Integration Testing. In the second part of this article, we will work with mockito to write tests for more complex apps. If you don’t want to miss this part, I recommend you follow me.

Anyways, let’s get started!

Happy reading!

Setup

The first thing we have to do after creating our app is to replace the main.dart with this code and create a new file called counter.dart and paste this code to follow along with this “tutorial”. Now, let’s navigate to our “test” folder and remove everything that is in the main function of widget_test.dart.

Unit Testing

Now we create a file, that we will call unit_test.dart. Every testing file should end with test.dart, so that Flutter knows, that this is a test file.

Okay, now let’s import the flutter_test package and our counter.dart as well as create a main function. Inside this, we will test our app:

--

--

Tomic Riedel

Sharing the process of building a portfolio of apps to make people more productive.