Automate tests in Insomnia
You can automate tests written in Insomnia by using the Inso CLI with the inso run test "document name" --env "environment name"
command.
Prerequisites
Inso CLI
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.
Create and configure a collection
For this tutorial, you’ll need a collection in Insomnia. A 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 collection to Insomnia:
This pre-configured collection contains:
- The example “Flights Service 0.1.0” spec added as a document
- A collection generated from the spec
- Pre-configured base environment variables
Write a test
Before you create a test, you need to create a test suite for the collection.
- To do this, click the Tests tab and click New test suite in the sidebar.
- 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);
- From the Select a request drop down, select the GET KongAir planned flights request.
- Click the Play icon next to your test. In the preview to the right, you should see that the test passes.
Run a test with Inso CLI in the command line
You can use the inso run test
command to execute 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
document 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.