The testing pyramid
Test classification using the test pyramid
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
- |
Lesson Transcript
[00:00 - 00:22] Let's talk about the testing pyramid, a framework for organizing your automated tests. The testing pyramid was originally proposed by Mike Kahn in his "Soxidin with Agia" book, published in 2009. The testing pyramid is a popular way to think about testing, because it provides a mental framework for thinking about tests and classifying them.
[00:23 - 00:58] The traditional testing pyramid is divided into three levels. At the bottom, you have unit tests. As the name suggests, this validates atomic units of code, which are usually functions, or procedures, or methods in OOP. These tests are the smallest and most gran ular and the test individual functions or classes. Unit tests provide the biggest feedback and highest confidence in isolated code. At the middle, you have service tests.
[00:59 - 01:31] These tests are larger than unit tests, and they test the interactions between different functions or units. They ensure individual functions or classes work together as intended. Service tests validate isolated pieces of business logic. At the top, you have the UI tests which verify functionality from a user's perspective by interacting with the app's interface . These tests are the largest and most comprehensive and they test the user interface of your application.
[01:32 - 02:10] It's also important to note that these tests are crucial, but slow, and they provide the highest guarantee. This categorization based on targets which are functions, service, or interface can be problematic. And instead, I suggest separating tests based on scope. In the revised testing pyramid, it is advised that you separate tests based on their scope and how frequently they run. In the revised testing pyramid, the larger scope is at the top with end-to-end tests.
[02:11 - 03:00] This simulates full user journeys through the app, interface, or API, containing many moving parts. Below the end-to-end test are integration tests which combine units into modules and services to test interactions. And at the bottom, you have unit tests which has the smallest scope, run very fast, and devallidate individual functions or classes in isolation. It is important to note that tests don't neatly fit into one category or the other. Many will blend between different levels of this pyramid. The overall goal is to guide our testing efforts and build a mental framework of the different types of tests that we have and how to properly classify them. After this, we'll get to install just. See you in the next lesson.