Introduction to testing
Last modified on Mon 10 Oct 2022

Why do we write tests? Writing tests has several benefits. Most important benefit for us that it makes better product for end users by reducing the number of bugs and regression issues.

Secondary benefits are focused on developers. It gives you more confidence that changing code will not suddenly break some functionality, and it also forces a developer to design a code in a testable manner.

What kind of tests?

Regarding the different kind of tests we can separate them into the categories:

Another separation is by layers: interactor tests, repository tests, presenter tests, util tests.

What do we test?

These test differentiate in amount of logic and complexity. Writing an intergration_test requires specific setup of whole your application so that everything can work. These tests are very complex.

Current minimum is to write tests for the pieces with most logic and least complexity:

Other tests are also welcomed, but right now focus is on making some required minimum. We will explain in few more details these tests in following pages:

Organizing tests

The folder structure of unit and widget tests should be the same as the folder structure of production code. The name of the test file should be the same as the name of the production file, with the _test suffix added (lib/common/string_util.dart -> test/common/string_util_test.dart).

The integration tests should be placed in a separate folder in the root of the app (integration_test/login_test.dart).