Creating Integration Tests for the Application

Learn how to encompass the integration tests for an application in Deno.

We'll cover the following

In this lesson, we’ll write integration tests for the login and register functionality. These are a little more complex than the tests we wrote previously for the museum’s module because they’ll test the application as a whole, including its business logic, persistency, and web logic.

The three tests we’ve written so far have been unit tests for a single module, and an integration test between two different modules. However, to be confident that our code is working, it would be useful if we could test the application as a whole. That’s what we’ll do here. We’ll wire up our application with a testing configuration and run a few tests against it.

Writing tests for integration testing

We’ll start by calling the same function we called to initialize the web server and then create instances of all its dependencies (controllers, repositories, and so on). We’ll make sure we use things such as in-memory persistence to do so. This will make sure that our tests are replicable and don’t need a complex teardown phase or a connection to a real database because that would slow down the tests.

We’ll start by creating a test file that, for now, will encompass the integration tests for the application. As the application evolves, it might make sense to create a test folder inside each module, but for now, this solution will work just fine.

We’ll instantiate the application with a setup that’s very close to what it runs in production and make a few requests and assertions against it:

  1. Create the src/index.test.ts file, alongside the src/index.ts file. Inside it, create a test declaration that tests that a user can log in:

Get hands-on with 1200+ tech skills courses.