What is the difference between unit, integration and end-to-end tests?
BeginnerConceptTesting in DevOps
Answer
In one line: Unit tests check one small piece of code in isolation, integration tests check that several pieces work together, and end-to-end tests check a full user journey through the whole system.
Unit tests
- Scope: one function, method or class.
- Dependencies: replaced with mocks or stubs (no real database or network).
- Speed: milliseconds.
- Who writes them: developers, alongside the code.
- Tools: JUnit, PyTest, Jest, Go's
testing, NUnit. - Example:
applyDiscount(price=1000, code="SAVE10")returns900.
Integration tests
- Scope: two or more parts together — app + database, app + message queue, service A calling service B.
- Dependencies: real or realistic (Testcontainers, Docker Compose, a test database).
- Speed: seconds to minutes.
- Example: calling
POST /orderssaves a row in PostgreSQL and publishes an event to Kafka.
End-to-end tests
- Scope: the whole system from the user's point of view.
- Environment: a deployed environment like staging.
- Speed: minutes; more likely to be flaky.
- Tools: Playwright, Cypress, Selenium.
- Example: a script logs in, searches for a product, adds it to the cart and completes checkout.
| Unit | Integration | End-to-end | |
|---|---|---|---|
| Scope | One unit | Several components | Whole system |
| Speed | Fastest | Medium | Slowest |
| Failure tells you | Exactly what broke | Which connection broke | That a journey broke |
| Count | Many | Some | Few |
In the pipeline: unit tests on every commit; integration tests on PRs or after build; E2E after deploying to staging.
Tip for interviews: give a concrete example of each from one app — that makes the difference crystal clear.
More on Testing in DevOps
What is the testing pyramid?BeginnerWhat are smoke tests and sanity tests?BeginnerWhat is regression testing?BeginnerWhat is test automation, and what should (and shouldn't) be automated?BeginnerWhat is shift-left testing, and how do you apply it in a pipeline?IntermediateWhat is contract testing, and why is it useful for microservices?Intermediate