CodingNic

Integration Testing an API

Module Overview

Integration Testing an API 5 min read

Module Overview

What You’ll Learn

  • Explain the difference between a unit test and an integration test
  • Use Supertest to send real HTTP requests to an Express app in tests
  • Write an integration test covering a full authenticated request

💡 Why this matters: Module 7’s unit tests check individual functions in isolation. This module checks something a unit test can’t, whether a real request, through real middleware, routes, and a controller, actually behaves correctly end to end.

What’s Covered

  • Unit versus integration tests, what each one actually proves, and what neither one does alone.
  • Supertest, sending real HTTP requests to an Express app without starting a real server.
  • Testing authenticated routes, logging in within a test, then using the result to test a protected route.
  • Testing error responses, confirming a 401, 403, or 400 comes back exactly when it should.

Hands-On

By the end of this module, you’ll have integration tests covering registration, login, and a protected route, both the success path and the correctly rejected failure paths.

Next module: logging and error monitoring, so failures in production are visible instead of silent.