Automate tests in Insomnia

TL;DR

You can automate legacy unit tests written in Insomnia by using the Inso CLI with the inso run test "<API Collection name>" --env "<environment name>" command.

Prerequisites

Download and install Insomnia.

The Inso CLI (Command Line Interface) allows you to use Insomnia application functionality in your terminal and CI/CD environments for automation. To complete this tutorial, you will need to install the Inso CLI.

For this tutorial, you’ll need an API Collection in Insomnia. An API Collection is essential for this tutorial to function, but creating one isn’t the focus of this guide. Use the following to add a pre-configured API Collection to Insomnia:

Run in Insomnia

This pre-configured API Collection contains:

Before you create a test, you need to create a test suite for the API Collection.

  1. If your API Collection doesn’t have a Tests tab, go to Preferences > General > Application and enable Show legacy unit tests.
  2. On the API Collection screen, click the Tests tab.
  3. In the sidebar, click New test suite.
  4. From the test suite you just created, click New test. Insomnia creates a default Return 200 request for you:
    const response1 = await insomnia.send();
    expect(response1.status).to.equal(200);
  5. From the Select a request drop down, select the GET KongAir planned flights request.
  6. Click the Play icon next to your test. In the preview to the right, you should see that the test passes.

v13.3+ Legacy unit tests are hidden by default.

If an API Collection already contains legacy unit tests, its Tests tab still appears automatically. Otherwise, to follow this guide, go to Preferences > General > Application and enable Show legacy unit tests, which shows the Tests tab on every API Collection.

For new work, use pre-request and after-response scripts instead. Scripts are the recommended way to test APIs in Insomnia.

Run a test with Inso CLI in the command line

You can use the inso run test command to execute legacy unit tests written inside Insomnia from your terminal or in a CI/CD environment. Once the command is executed, the Inso CLI will report test results and exit with an exit code.

Run the following to test the Flights Service 0.1.0 API Collection in the OpenAPI env api.kong-air.com environment:

inso run test "Flights Service 0.1.0" --env "OpenAPI env api.kong-air.com"

You should get a report saying which tests were conducted and that the one test you set up passed. For example:

  New Suite
    ✔ Returns 200 (1576ms)


  1 passing (2s)

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!