Understanding Integration Tests

Integration tests are required when we want to check that our code is interacting correctly with other systems. Most of the time this means sending proper HTTP requests and handling the responses correctly.

The best way of doing these type of tests is by calling a server that is scripted so that the interaction with it is deterministic. We analyze what the app would request in a given scenario and script the server to respond in a certain way.

And to have a completely deterministic script it is necessary to have the server running in the same machine as the tests, and have everything (including the responses) in the code base along with the tests. This way we remove variables like network connectivity or someone modifying a remote server breaking the expected behavior.

It’s also important to mention that the mock server should run in any available port (not a specific one), so that we remove scenarios where the tests would fail because the expected port is already binded.