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:

  1. Add either the test or flutter_test dev dependency.

  2. Create the function or class to test.

  3. Create a test file and write tests.

  4. 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.