Testing Levels: Unit, Integration, and E2E

Understand the testing pyramid and where to focus your efforts using Jest and Cypress.


Testing Levels: Unit, Integration, and E2E
1 Loading...

Testing Levels: Unit, Integration, and E2E

Not all tests are created equal.

1. Unit Tests (Jest/Vitest)

Test individual functions in isolation.

  • Fast, cheap, specific.
  • Example: Testing a sum(a, b) function.

2. Integration Tests

Test how modules work together.

  • Medium speed.
  • Example: Testing a database query combined with an API endpoint.

3. End-to-End (E2E) Tests (Cypress/Playwright)

Test the application as a user (clicking buttons in a browser).

  • Slow, expensive, flaky.
  • Example: Logging in, adding an item to cart, and checking out.

The Pyramid

You should have many unit tests, some integration tests, and few E2E tests.