Automated tests are divided into unit, integration, and end-to-end (E2E) to comprehensively cover the checking of the system at different levels.
History of the issue: This classification arose from the need to test applications both in parts and as a whole. Therefore, testing layers are distinguished:
Problem: Errors often arise not only in the logic of an individual method but also at the component interfaces or during the "real" launch of the entire system with external services. If everything is mixed up, it is hard to quickly localize a bug or understand where it came from.
Solution:
Distinguishing between test types is vital to:
Key features:
Can integration tests be considered just "big" unit tests?
No, integration tests test the operation of several components together, not just individual functions. In this case, it is not always possible to use mocks — real services interact with each other.
Should all tests be end-to-end (E2E)?
No, this is an expensive and complex approach. E2E tests are only needed for critical user scenarios; most logic is covered by other tests.
Are unit tests always fast?
Not always. Sometimes it is not possible to isolate the code, or a method depends on complex external resources. In such cases, the test ceases to be a unit.
The company only covered the main functionality with E2E tests — each fix was checked overnight, tests failed unstably, and bugs were discovered late.
Pros:
Cons:
The team built a testing pyramid: the bottom — unit tests, the middle — integration tests, the top — only the most important E2E.
Pros:
Cons: