- How to add assertions and expectations to HTTP scenarios with
- How to use the plugin to run functional tests for your API with Artillery
- Add expectations and assertions to your HTTP scenarios
- Use the same
artillerycommand to run functional / acceptance tests on your APIs
- See details of any failed assertions (request headers & body, response etc)
- Use your Artillery scenarios for both functional testing and load testing
- Run post-deployment smoke tests from CI/CD pipelines
npm install -g artillery-plugin-expect
To enable the plugin, add it to the
config section of a test script.
Run your script that uses expectations with:
artillery run --quiet my-script.yaml
--quiet option is to stop Artillery from printing its default reports to the console.)
This plugin allows for the same scenario to be re-used for either load testing or functional testing of an API, with the help of
config.environments definition in your test script.
(The only real difference between the two, of course, is how many virtual users you run – only one for functional tests, and lots of virtual users for a load test.)
You could run the script above in load testing mode with:
artillery run --environment load script.yaml
and in functional testing mode with:
artillery run --environment functional script.yaml
Check that the status code of the response.
The value may also be a list to indicate that any of the codes in the list is OK:
Check the value of
When the response is JSON, check that the response object has a property (or does not in case of
notHasProperty). Same behavior as
Check that two or more values are the same. NOTE only primitive values (e.g. booleans, strings and numbers) are currently supported.
Check that the response contains a header.
Check that the response contains a header and its value matches some string.
Check that response body matches a regular expression. The regular expression provided must be a string which is a valid argument to the RegExp constructor.
If you’re having issues with the plugin, you can print out helpful debugging messages using the
DEBUG environment variable.
DEBUG=plugin:expect when running your tests to view when using an expectation and any values to check.
DEBUG=plugin:expect artillery run my-script.yaml
The source code for
artillery-plugin-expect is available on Github at https://github.com/artilleryio/artillery-plugin-expect. It’s an officially supported plugin and we’d love to hear your feedback and ideas for improvement.