Unit Testing for Voice Apps

To make sure your Alexa Skills and Google Actions are robust, we highly recommend testing. Learn how to implement unit tests for your voice apps built with Jovo.

Introduction to Unit Testing

Unit Testing is a testing method that allows you to make sure individual units of software work as expected. This way you don't have to manually test every potential interaction of your voice app after any change you do to the code, which not only saves a lot of time, but also gives you some well deserved peace of mind.

The Jovo TestSuite allows you to create unit tests for your Alexa Skills and Google Actions that can either test certain individual features, or even full conversational sequences.

Getting Started with the Jovo TestSuite

Use the Jovo Unit Testing Template to get started with some first tests.

Here's everything you need to know to get started:

Install Jest

Since Jovo v2, every new Jovo project comes with Jest as dev dependency and sample tests.

The Jovo TestSuite builds on top of Jest, a popular Javascript testing framework.

You can add Jest as dev dependencies like this:

Create Test File

You can find an example test project here.

Unit tests are usually located in a test folder of your Jovo project. Naming conventions are <name>.test.js.

This is how a sample sample.test.js file with a single test for both Amazon Alexa and Google Assistant could look like:

Run Test Script

After you've defined some first tests, add the following script to your package.json:

This way, you can run the tests with npm test. Don't forget to first start the Jovo webhook:

Basic Concepts

Tests can be run for each platform:

After initializing the TestSuite, you can add test groups like this:

Conversation

Each test starts with a conversation:

Conversation Configuration

You can also add certain configurations to the constructor of your conversation object.

Here is a list of the default configurations of the conversation object:

Request

Request Builder

You can use the request builder of the testSuite to build a request. The following request types are supported:

  • launch
  • intent

After creating a request with the request builder, you can modify with several helper methods:

Find out more about the helper methods for the Jovo $request object here.

Response

The previously created requests can be sent to the conversation. This will then return a response:

You can then used these responses to compare them to expected results (see section Check below):

Find out more about the helper methods for the Jovo $response object here.

Check

Learn more about Jest Expect here.

Data

Delete the database for this user with the following method:

Comments and Questions

Any specific questions? Just drop them below. Alternatively, you can also fill out this feedback form. Thank you!

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.