Insomnia does not have a built-in capability for stress-testing, however there are plenty of tools to do so. Please refer to these following links for further information and use:
The remainder of this document covers how to use the Unit Testing functionality within Insomnia. Currently, unit testing is only available to Design Documents, although you don’t strictly need an OpenAPI specification to write them.
Unit tests in Insomnia rely on the Chai framework.
You can test the response payload by accessing the .data
attribute of the response variable:
const response = await insomnia.send();
expect(response.data).to.be.an('string');
By default, response.data
will be a string. If you want to validate it as JSON, you must first convert response.data
to JSON using JSON.parse
:
const response = await insomnia.send();
const body = JSON.parse(response.data);
expect(body).to.be.an('array');
Since unit tests rely on the Chai library for unit testing we can test properties easily once we have converted our response payload to JSON:
const response = await insomnia.send();
const body = JSON.parse(response.data);
const item = body[0];
expect(body).to.be.an('array');
expect(item).to.be.an('object');
expect(item).to.have.property('id');
Chaining requests is as simple as following the request chaining guide, and then selecting the chained request from the Select Request dropdown.
Since unit tests rely on the requests and the selected environment under the debug tab, the only way to alter a request being made in a unit test is to alter the request, and its environment variables under the debug tab.
Now that we have opened DevTools and have the console open, we can console.log
values in our unit test to the console:
const response = await insomnia.send();
const body = JSON.parse(response.data);
const item = body[0];
console.log(item);
Run unit tests in CI (like GitHub Actions or Azure DevOps) using git sync and Inso CLI with the inso run test
command.
Rename a unit test by double clicking on the unit test’s name and changing the contents.
The value is saved when you click outside the editable area.
Delete a unit test by clicking the Delete icon next to a test.