Ready to get started?

Join Adocasts Plus for $8/mo, or sign into an existing Adocasts Plus account, to get access to all of our lessons.

robot mascot smiling

Pragmatic Testing in AdonisJS with Japa #5.0

Database Test Runner Hooks

In This Lesson

We'll learn how to set up a dedicated test database to ensure clean, isolated testing. We'll configure a separate SQLite database using a test environment variable and set up Japa runner hooks to automatically migrate and seed our database

Created by
@tomgobich
Published

When it comes to tests using a database, we're going to want to test on a database separate from our actual application. We want to test in a clean setup so that if we have a test that creates a user with the email test@test.com that test doesn't get hung up because:

  • We created that user in development

  • That user is still dangling around from a previous test run

  • Anything else in between

To resolve this, first, we're going to want to set our test environment to use a completely different database from our dev server. If you're not using SQLite, then you'll want to make a database for testing. I typically do the normal database name, suffixed with _test, like adocasts_test.

Join the Discussion 0 comments

Create a free account to join in on the discussion
robot comment bubble

Be the first to comment!