What Is an Integration Test?

Testing Elixir — by Andrea Leopardi, Jeffrey Matthias (21 / 80)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Chapter 2 Integration and End-to-End Tests | TOC | Testing Against Real External Dependencies 👉

Tests that cover the integration of different components (be they external systems or different parts of an application) are often referred to as integration tests. In this book, when we use the term integration test, we mean a test that covers a piece of code that calls out to two or more parts of a system or external systems. Integration tests are fundamental to testing a system. Unit tests give you confidence that your functions and modules behave correctly; but you’ll need to test that your system functions correctly as a whole, and to do that you need to test the glue between the components of the system. Let’s start by looking at an example of integration testing.

A common scenario in HTTP-based web applications is having a router that routes requests to different functions based on the request URI. Those functions are usually contained in modules called controllers. A controller function is responsible for doing any necessary manipulation on the request data, formulating an output, and sending a response back to the client. The code for the router and the controller could look something like this:

integration_tests/pseudocode_controller_and_router.ex

​ ​defmodule​ MyApp.Router ​do​
​ route(​"​​POST"​, ​"​​/perform_action"​, {MyApp.Controller…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.