Flutter Testing— Understand Unit, Widget, and Integration Testing | by Aditya Rohman | Feb, 2022

A practical guide to common testing types in Flutter such as unit testing, widget testing, and integration testing.

Photo by Balázs Kétyi on Unsplash

There are 3 types of testing methods that are commonly implemented in a Flutter project:

Unit Testing

Unit testing is a type of testing on an application where testing is focused on what is called a unit. Unit is the smallest part that builds up the application. The simplest examples of units when we talk about OOP (Object-Oriented Programming) are Class and Function. Unit testing will ensure that small components of an application run well and as expected.

test('description', () {});
  • Assert — the stage where we validate the action that has been executed whether it is in accordance with what is expected or not. In the above example, when the data is successfully retrieved from the API we validate the result of the getNowPlayingMovies() function call is equal to the movie list.

Widget Testing

Widget testing or in other terms called instrumentation testing is a type of testing that is focused on the parts that build the User Interface of an application such as buttons, text fields, and so on. Widget testing will ensure that the User Interface is laid out according to the UI design of the application and can interact well with the user.

testWidgets('description', (WidgetTester tester) {});

Integration Testing

Integration testing is a type of testing that is focused on testing the entire flow of the application (end-to-end testing). To run integration testing, you need an emulator or real device. During testing, the application will appear on the emulator or real device and run the application automatically.

dev_dependencies:    
...
integration_test:
sdk: flutter
integration_test
├── app_test.dart
└── robots
├── home_robot.dart
└── ...
flutter test integration_test
Integration testing result

In conclusion, when developing an application, consider testing as much as possible. So that the final results of the application can be measured properly and facilitate maintenance when there are features that you want to revamp or fix.

Leave a Comment