# Integration and End-to-End Testing

> Test your API against real databases and dependencies, and verify full user flows end to end. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/integration-e2e-testing
Last updated: 2026-11-28

Test your API against real databases and dependencies, and verify full user flows end to end.

Intermediate · about 8 hours · difficulty 3/5

Learn first: [Unit Testing Fundamentals](https://www.internhack.in/roadmaps/tracks/backend/unit-testing), [Resource-Oriented REST APIs](https://www.internhack.in/roadmaps/tracks/backend/rest-api-design)

Unit tests prove your logic; **integration tests** prove the pieces work together: your code with a real database, a real HTTP layer, a real queue. **Functional or end-to-end (e2e) tests** exercise complete user flows from the outside, the way a client would.

### Integration testing an API

- Start your app in-process and send real HTTP requests (Supertest, FastAPI TestClient, Spring MockMvc, WebApplicationFactory).
- Use a **real database engine**, not a mock. **Testcontainers** spins up PostgreSQL, Redis or Kafka in Docker per test run.
- Reset state between tests with transactions that roll back, truncation or a fresh schema.
- Test the unhappy paths: validation errors, auth failures, conflicts.

### End-to-end tests

Run the deployed system (or a production-like staging) and drive it through user journeys: sign up, create an order, receive an email. For APIs this can be a collection of HTTP scenarios; for full-stack apps, browser tools like **Playwright**. Keep e2e tests few and focused on critical paths because they are slow and more brittle.

### Contract tests

In multi-service systems, **consumer-driven contract tests** (for example Pact) check that a provider still satisfies what its consumers expect, without deploying everything together.

### The shape of a good suite

Many unit tests, a solid layer of integration tests, and a thin layer of e2e tests. Many backend teams find integration tests give the best confidence per minute.

You are ready to move on when your API has integration tests against a real Postgres in Docker that run in CI in under a few minutes.

## Key concepts

- **HTTP-level API tests**
- **Testcontainers**
- **Test data and database reset**
- **End-to-end user journeys**
- **Playwright**
- **Contract testing with Pact**
- **Load testing (k6)**

## Mini project

Write integration tests for your API's signup, login and create-resource endpoints against a Testcontainers PostgreSQL, including tests for 401, 403 and 422 responses.

## Check yourself

Why can mocking the database in API tests give false confidence?

## Free resources

- [Testcontainers](https://testcontainers.com/) (Testcontainers)
- [Playwright documentation](https://playwright.dev/docs/intro) (Microsoft)
- [Pact documentation](https://docs.pact.io/) (Pact)

Previous: [Unit Testing Fundamentals](https://www.internhack.in/roadmaps/tracks/backend/unit-testing) · Next: [Test-Driven Development](https://www.internhack.in/roadmaps/tracks/backend/test-driven-development)

## More in Testing and Shipping Continuously

- [Unit Testing Fundamentals](https://www.internhack.in/roadmaps/tracks/backend/unit-testing)
- [Integration and End-to-End Testing](https://www.internhack.in/roadmaps/tracks/backend/integration-e2e-testing)
- [Test-Driven Development](https://www.internhack.in/roadmaps/tracks/backend/test-driven-development)
- [Continuous Integration and Delivery](https://www.internhack.in/roadmaps/tracks/backend/ci-cd)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
