There are several types of Flutter Tests that you could use to verify different aspects of your logic in your applications.
Unit Tests
Similar to unit tests in other programming languages, these tests isolate individual units of code (e.g., functions or classes) to ensure they work correctly. They’re useful for testing business logic, API calls, and other non-widget-related code. Unit Tests – test small functionality that has strict input-output requirements. Great Examples may be – business calculations, encryption, etc
BloC Tests
In many cases the business logic is hard to be extracted as Services. BloC Tests are unit tests that verify the changes in the stream that is transfered from the Controller to the UI. There are of course different variations of MVC/BloC, but BloC is one of the most popular. Bloc tests – verify expected state of BlocState during/before/after BloC Events.
Widget Tests
These tests verify that widgets behave as expected when interacting with them programmatically. They’re written using the flutter_test
package and allow for testing of widget logic, such as button clicks, text input, and scrolling. Widget Tests – for testing the presence in the tree – the UI elements you are building.
Golden Tests
The golden toolkit is discontinued package https://pub.dev/packages/golden_toolkit. Most probably someone will pick it up and continue development. Golden Tests – test pixel perfect output of your widgets onto phones, tablets, etc – with png files. It is typical to verify the common 4 states in a screen
- loading
- error
- empty
- loaded
The tests described so far you execute in command line mode and do not need an emulator or virtual machine. For next – level verification – you could assert logic and UI when your app is runing on top of simulators.
Integration Tests
These tests could check the state of your app – when it runs on emulator – with less mocked layers. https://github.com/flutter/flutter/tree/main/packages/integration_test. They are executed with drivers – that bridge the Test Verification logic inside the Flutter Engine.
UI Test Automation
Taking advanges of the same idea are the different implementation of the UI testing tools. This type of testing uses tools like Appium, Espresso or Patrol to automate UI interactions, such as scrolling, tapping, and entering text. These tests can help ensure that your app’s UI works correctly across different devices and platforms.