The test pyramid

An important metaphor to keep in mind when thinking about software testing is theĀ test pyramid. The idea behind it is that we can regroup the different types of tests based on their cost and their execution speed. Based on that segmentation or order, we should write enough cheap tests to cover most of the functionality and cover the rest with other types of tests.

At the base of the pyramid are the unit tests, which are very cheap to create and maintain and are also the fastest to execute. At the top of the pyramid are the end-to-end tests and manual tests, which are more complex to create, much more costly to maintain, and are also slower to execute:

You should always have at least a set of unit tests. Then, depending on the scenarios, you might also need to write integration tests and end-to-end tests to properly cover the different flows.