Testing AdonisJS

Testing AdonisJS

35mins
6 lessons
Beginner
Start course

Whether you care to admit it or not, we are already performing testing one way or the other. You implement a feature then open up a browser to see if it works. Yeah! That's you testing but manually. In this course, we are going to cover automating that process by writing tests for every piece of functionality in our application. Having automated tests gives us the confidence that our application is working as intended.

We cover things like writing tests that integrate with the database, testing sending emails, events and so much more. While there are different types and strategies of testing, in this course, we'll be adding tests to an existing application and covering mainly integration tests with a couple of unit tests.

Getting Started

We'll start by familiarizing ourselves with the concept of testing and then set up our AdonisJS application for testing using the Japa test runner.

What you'll learn

  • What is testing
  • Benefit of testing
  • Set up the Japa test runner in an AdonisJS application

In the last lesson, we wrote a very basic test. In this lesson, we are going to look at how to run our tests.

What you'll learn

  • Running all tests
  • Running a single test

We have seen how to run tests, but there are times you'd prefer to have your tests running in watch mode. So whenever you make changes to a test file, the tests are rerun automatically. In this lesson, we'll cover how to achieve that using Nodemon.

What you'll learn

  • How to run tests in watch mode using Nodemon

During testing, AdonisJS will look for a dedicated test environment file called .env.testing to fetch environment variables from. In this lesson, we create the file and take a closer look at it.

What you'll learn

  • Use a dedicate test environment file

When building a non-trivial application, chances are we'll need to interact with a database in our tests. In this lesson, we are going to look at how to configure the Japa test runner to interact with a database. We'll be covering two ways to achieve that.

What you'll learn

  • Configure Japa to interact with a database
  • use a dedicate database for testing
  • Run migrations programmatically

Tests

With all the setup out of the way, let's start writing actually tests for our application. In this lesson, we'll start with a unit test that will test the User model to ensure users' passwords are hashed when saved to the database.

What you'll learn

  • What is a unit test
  • What is a integration test
  • Running migrations on a need-to basis
  • Ensure each test starts on a clean slate
  • Write your first AdonisJS test

*Course still in development. Do check back often for updates.

Chimezie Enyinnaya

Hi, I'm Chimezie Enyinnaya, your teacher.

I’m a self-taught software developer based in Lagos, Nigeria, with over 8 years of experience. In the last couple of years, I've been doing more teaching because I enjoy sharing my knowledge so that others can benefit from it. Come along as I teach you all I know about AdonisJS, Node.js, and JavaScript at large!