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:
- unit test (tests a single function, method, or class.)
- widget test (tests a single widget, including Golden tests)
- integration test (tests a complete app or part of the app)
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:
- Static utils tests
- Interactor tests
- Presenter tests
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:
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,
_test suffix added (
The integration tests should be placed in a separate folder in the root of the app