Writing an Integration Test

Learn how to write an integration test in Deno.

In this lesson, we’ll write more interesting tests. These are the tests that will teach us how to check the integration between the different modules of the application.

Integration test

Our first unit test, which we created previously, relied on a mocked instance of the repository to guarantee that our controller was working. That test adds great value when it comes to detecting bugs in MuseumController, but it isn’t worth much in terms of understanding if the controller works well with the repository.

That’s the purpose of integration tests: they test how multiple components integrate with each other.

Integration tests for MuseumController and MuseumRepository

We’ll write the integration test that tests MuseumController and MuseumRepository. These are the tests that will closely mimic what happens when the application runs and will help us later in terms of detecting any problems between these two classes.

Let’s get started:

  1. Create the file for this module’s integration tests inside src/museums, called museums.test.ts, and add the first test case there.

    It should test whether it’s possible to get all the museums, this time using an instance of the repository instead of a mocked one:

Get hands-on with 1400+ tech skills courses.