Testing the Flutter Application
Learn to test the Flutter application.
We'll cover the following
Testing is the process of evaluating and verifying that our application does what it is supposed to do. It ensures the application meets both technical and user requirements.
The advantages of testing applications include:
Preventing bugs
Reducing development cost
Improving performance
Types of tests
There are three categories of tests that we can write for our Flutter application.
Unit tests
Widget tests
Integration tests
Unit tests
A unit is a minor testable component of an application. Unit tests test a single function, method, or class to verify the correctness of logic units with various conditions.
Unit tests do not write to disk, render to screen, or receive user actions from outside the process running the test. During unit tests, we mock the external dependencies of the unit under test.
To perform a unit test, we follow the steps below:
Add either the
test
orflutter_test
dev dependency.Create the function or class to test.
Create a test file and write tests.
Run the tests.
As part of our unit tests exercise, we will exercise our understanding of testing by writing and testing an email validator. Find your starter app containing tasks to complete the exercise below.
Note: The code widget below will not run correctly until you have completed steps 1, 2, and 3.
Get hands-on with 1400+ tech skills courses.