Understanding Unit, Widget, and Integration Testing in Flutter
As an application gains more features, manual testing becomes increasingly difficult. Automated testing helps ensure that your application works correctly before you publish it, while maintaining features and the speed of bug fixing.

Categories of Automated Testing
Automated testing is divided into three categories:
- Unit test: Tests a single function, method, or class.
- Widget test: (In other UI frameworks called component testing) Tests a single widget.
- Integration test: Tests a complete application or a large part of the application.
Generally, a well-tested application has many unit and widget tests, which are tracked based on code coverage, plus enough integration tests to cover all important use cases. This advice is based on the fact that there are trade-offs between different types of tests.
Read Also: What is TDD (Test Driven Development)
Unit Tests
Unit tests verify the correctness of a single unit of logic under various conditions. External dependencies of the unit being tested are generally mocked out. Unit tests usually do not read from or write to disk, render to the screen, or receive user actions from outside the process running the tests. For more information on unit tests, run flutter test --help in your terminal.
Resources:
Widget Tests
The goal of a widget test is to verify that a widget’s UI looks and interacts as expected. This involves multiple classes and requires a test environment that provides the appropriate lifecycle context.
For example, the widget being tested must be able to receive and respond to user actions and events, perform layout, and instantiate child widgets. Therefore, widget tests are more comprehensive than unit tests. However, the environment is much simpler than a complete UI system.
Resources:
Integration Tests
Integration tests verify that all widgets and services being tested work together as expected. Furthermore, you can use integration tests to verify your application’s performance.
Generally, integration tests run on a real device or OS emulator (like the iOS Simulator or Android Emulator). The application being tested is usually isolated from the test driver code to avoid skewed results.
Resources:
Continuous Integration Services
Continuous Integration (CI) services allow you to run tests automatically when pushing new code changes. This provides timely feedback on whether code changes work as expected and don’t introduce bugs.
For more information, see: